Knowledgebase

301 https redirect www. and non-www.  Print this Article

To insure your website displays your SSL certificate all the time, please add one of the following codes to the top of your ".htaccess" file located in the public_html folder. This will be located in the file directory of your hosting panel. Be sure to enable hidden ".(dot)" files to see this file. If the ".htaccess" file is not present simply create it. Be sure to create a backup of this file in case you need to revert the changes. 

**Replace "exampledomain.com" with your domain.
Note: Depending on the servers setings you may need to remove "RewritEngine on" or add a "#" directly before it to comment it out.

RewritEngine on
#rewrite to https and www.
#First we turn on https if its off
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Second, we rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} ^exampledomain.com [NC]
RewriteRule ^(.*)$ http://www.exampledomain.com/$1 [L,R=301]
#Result: https://www.exampledomain.com
RewritEngine on
#rewrite to https and NON-www.
#First we turn on https if its off
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Second we rewrite any request to the wrong domain to use the correct one (here NON-www.)
RewriteCond %{HTTP_HOST} !^exampledomain.com$ [NC]
RewriteRule ^(.*)$ http://exampledomain.com/$1 [L,R=301]
#Result: https://exampledomain.com
RewritEngine on
#Turn on https if off
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Result: https://exampledomain.com or https://www.exampledomain.com

For more information please view our
complete guide to SSL and SEO.

Was this answer helpful?

Related Articles

SSL Installations
SSL installation depends on the type of server you are securing. Please select below the server...
Apache (with mod_ssl)
Installing SSL certificate on Apache with mod_ssl To install certificate you need 2...
Apple Mac OS X Server
Log in to admin server as a root. Create a folder /etc/httpd/ssl.crt/ (if it does not exist)....
Barracuda VPN server
Installing SSL certificate on Barracuda VPN serverImport CertificatesFrom the appliance web...
Cisco ACS Server
Note: If the domain/site certificate is created using CA certificate, you need to repeat steps...