Forcing HTTPS and/or WWW

NOTE: This article is offered to help customers who are attempting to fix a common problem. We have found this solution to be helpful, but it is not a guaranteed fix, and it is not our area of expertise. If this does not fix your problem, please consult a web developer professional for further assistance.

 

Redirect HTTP to HTTPS automatically

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

Linux-based & cPanel accounts use .htaccess files to handle redirection. Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
# Rewrite to HTTPS:
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect to WWW. automatically

You can automatically redirect visitors to the WWW. version of your website to make sure they have a consistent experience.

Using the following code in your .htaccess file automatically redirects visitors to the WWW version of your site:


RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
# Rewrite to WWW.:
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect to HTTPS and WWW. automatically

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) and WWW. version of your website to make sure their information is protected and their experience is consistent.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS & WWW version of your site:


RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included,
# if not the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]