Using .htaccess to force https

Many occasions you need to push for an https URL (SSL) – here’s how we can do it using .htaccess

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

Please note this also ensures www on the domain at the same time!

Leave a Reply

Your email address will not be published. Required fields are marked *