Please add the following code in your .htaccess file to automatically redirect visitors to the HTTPS version of your site:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The above code will redirect [http://yourdomain.com] to [https://yourdomain.com] and [http://www.yourdomain.com] to [https://www.yourdomain.com].
To force a www redirect, use the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
The above code will redirect [http://yourdomain.com], [http://www.yourdomain.com], and [https://yourdomain.com] to [https://www.yourdomain.com].
If you have an existing .htaccess file:
- Do not duplicate RewriteEngine On.
- Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.