
Suppose that you have a website and the URL is https://www.mysite.com and you want to make it so that no matter what URL your website visitor uses for your site, they always end up at the https://www version of your site. For example mysite.com.com/page would become https://www.mysite.com/page, www.mysite.com/page would become https://www.mysite.com/page, https://mysite.com/page would become https://www.mysite.com/page, etc. The code below will show you how to achieve this. Note that the code should go in the .htaccess file in your root folder.
The Code
1 2 3 4 |
RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] RewriteRule ^(.*)$ https://www.mysite.com/$1 [L,R=301] |