Force HTTPS redirection


Question : How do I force redirection from http to https on premium or free hosting.

Answer : in your sites .htaccess file add the following lines :

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

You may use the following lines to force both HTTPS and WWW :

RewriteEngine On
RewriteCond %{ENV:HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www.YOURDOMAIN.COM$ [NC]
RewriteRule ^(.*)$ https://www.YOURDOMAIN.COM/$1 [L,R=301]