Force HTTPS for entire website via htaccess

From Brian Nelson Ramblings
Jump to: navigation, search

Force HTTPS for Entire Website via htaccess

With the most recent race to securing the web by google, we are seeing more and more people wanting to force their site to be served for https/443.

You can do this in your htaccess or vhost file by adding the following.

   RewriteEngine On
   RewriteCond %{SERVER_PORT} !^443$
   RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

With the above example it does not matter the url as it will redirect all requests to https://