Use .htaccess to force SSL and WWW prefix

Just a quick snippet showing how to force the HTTPS protocol (SSL) and the “www” sub-domain…

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]

There are other ways to achieve the same result, but I find this method is clean and requires the least amount of overhead to incorporate.

Leave a Reply

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