How to Force SSL with htaccess

Now days web security require each domain to use Secure Socket Layer SSL certificate. There are plenty available on the market from free to ones very expensive. Check our blog if you need to install SSL on your domain or on WHM server.

Now when you have SSL on your domain you need to route all the traffic via HTTPS protocol. This needs to be done for several proposes:

  • to ensure all traffic is encrypted and secure
  • to avoid double content pages (titles and meta descriptions)

To force an HTTPS connection on a website just add these simple rules in your website's .htaccess file:

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

This .htaccess file must be placed inside a website's document root folder. If website is in a sub folder, then the .htaccess should be placed in the corresponding sub folder.