htaccess redirect to SSL, www to non-www

So today I have installed a SSL certificate on this domain. The reason is not that important, but the idea is that I wanted to force redirect the non-secure (non-ssl) version to the secure (ssl) one.

So when someone tries to access http://truefreelancer.com, he/she will be taken automatically to https://truefreelancer.com

In the same time, i wanted to ditch out the www version, so when someone tries to access www.truefreelancer.com, he/she will be taken to the same https://truefreelancer.com

Here’s the most simple and efficient htaccess rule:

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

Share This Post