How To Redirect Your Website Using 301 Redirects

Jan 30, 2020

Non-Secure Redirects

non-www to www

Google Chrome recently started hiding the www portion of the URL, but if you want your website to work via instead of, you can achieve this via 301 redirect. You will need to add following code to the beginning of your .htaccess file:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^ [NC] 
RewriteRule ^(.*)$$1 [L,R=301]

Make sure to replace with your actual domain name. Once you save the file, your website will be automatically redirected from to

www to non-www

To redirect your website from to, input following code to the beginning of your .htaccess file:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^ [NC] 
RewriteRule ^(.*)$$1 [L,R=301,NC]

Secure Redirects

Redirect Entire Domain to HTTPS

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect Entire Domain from HTTP to HTTPS & non-www to www

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteCond %{HTTPS} off 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

In all cases, make sure to always place the code at the beginning of your .htaccess file in public_html directory.