Using Htaccess to redirect www to non-www

Whether you decide to use www as a subdomain or not, whats important is that you add a redirect from other option to your desired preference.

I prefer to use the non-www version, but it has no SEO benefit using either. The important thing like with the trailing slash you need to decide which you prefer and redirect it.

This can also be done in the htaccess file and once done you can forget about it.

htaccess redirect www to non-www

The below option also does the HTTP to https (I am assuming in 2019 you are using https, as there are so many positive reasons to use https and I can’t think of any real negatives.

The below is the code I use on my websites.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

htaccess redirect non-www to www

Again the below code just needs adding to you htaccess file and will redirect non-www traffic to the www version of your site.

# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Its very simple code, in a future video showing you how to actually edit your htaccess file, it does require you having access to the server.

Do you have any technical questions, why not ask in our Facebook group and I will be more than happy to help.


Share on facebook
Share on twitter
Share on pinterest
Share on linkedin

Leave a Comment

Your email address will not be published. Required fields are marked *

On Key

More Great Articles

SEMRush Bots

SEMRush Bot

SEMRush is a tool which you can use to crawl your website to analyse to find technical issues with what’s wrong on the website. SEMRush

Read More »

Technical Seo Demystified: Martin Splitt can’t be loaded because JavaScript is disabled: Martin Splitt – Technical SEO Demystified | AngualrUP 2019 ( This is a great talk from one

Read More »

Subscribe to my newsletter

Every Month I give away on FREE technical Audit for just being on our mailing list. For Full Terms check out our Terms and Conditions page.We will never sell your email or SPAM you.

Subscribe to our mailing list

* indicates required
WhatsApp chat