Skip to content

HTTPS redirect

November 12, 2011
By Administrator in All, Apache server

This short article will show how to easily redirect all requests to your website to go via the secure HTTPS protocol. Please, note that if you intend to do that, you need to make sure that your Apache web server is configured to accept secure connections and an SSL certificate is installed. Otherwise, you might render your website inaccessible.

The desired HTTPS redirect is as simple as putting the lines below into the .htaccess file in your website’s document root folder:

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ "https\:\/\/www\.example\.com\/$1" [R,L]

As you can see, we use mod_rewrite to redirect any non-SSL requests to go via the desired HTTPS protocol. The special server variable %{HTTPS} makes it very convenient to match all insecure requests in the RewriteCond directive. Of course, you should replace with your own domain name, making sure that all special characters are escaped with a backslash, just as in the example above.

That’s it :)

Tags: , , , , , ,

Comment Feed

No Responses (yet)

Some HTML is OK

or, reply to this post via trackback.