Force HTTPS on Apache 2

If you would like to force the entire site to use SSL:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]

or
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]

For a directory:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^directory/(.*)$ https://%{SERVER_NAME}/directory/$1 [R,L]
  • 27 Users Found This Useful
Was this answer helpful?

Related Articles

Java Keytool: commands

Deleting a certificate:  keytool -delete -alias aliasname List all of the...

How do I make my own bundle file from CRT files?

You may do this using you favorite text editor or by using the command line.Example: #...

Convert certificates formats (PEM/P7B/PFX/DER)

You can change certificate format using OpenSSL commands or SSL Converter tool. The...

Changing .crt file into the .cer format

Double-click on the yourwebsite.crt file to open it into the certificate display. In a new...

Converting .pfx file for use with Apache

Run the following command with open SSL:  openssl pkcs12 -in mypfxfile.pfx -out...