How to redirect your website using 301 redirects?

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.

Got Questions?

The Skystra team is always happy to help you out, we’re experts ;-). Just click the “Connect” button on the bottom right of the page and choose “Chat With Us.” We’re available, 24/7!