Redirect non-www to www and HTTP to HTTPS using htaccess

Below snippet shows how to redirect a site from non-www to www (or viceversa) and from HTTP to HTTPS. To be more clear, the configuration will redirect the following host names:


I’ll also show a small change to redirect the www to the non-www version, if you prefer the non-www.

To configure the redirects, add the following redirect rule either to the Apache config file if you have access to it, or to the .htaccess in the root of your site:

If instead of you want the default URL to be, then simply change the third and the fifth lines: