If you have a secure SSL on your site, you can automatically redirect visitors to the secure (HTTPS) version of your site to ensure that their information is protected.
The way visitors are redirected depends on the type of hosting you have .
Note: These instructions do not apply to WordPress installed in cPanel. For more information, see the topic
Linux-based accounts use files .htaccessto handle redirection.
If you do not have a file .htaccess:
Start by creating a file .htaccessin the public_html or webroot folder . Within the file .htaccess, you can use the following code to redirect visitors, provided you have not already set up a file .htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]
OR
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If you host multiple sites in the same account, you need to make sure that you have set up a file .htaccessin the directory of the site on which an SSL certificate has been issued. You need to replace coolexample.com with your domain name to run the sample code.
If you have a file .htaccess:
- Do not make a copy of it
RewriteEngine On. - Make sure the lines begin with
RewriteCondandRewriteRulelie immediately after the existing onesRewriteEngine On.



