Picking A Preferred Domain (www or non-www) & Setup 301 ReDirect


Picking A Preferred Domain (www or non-www) & Setup 301 ReDirect

Probably THE most important part of your site is your domain.  However, everyone seems to forget about this once they have bought it and then just concentrate on the site itself, but this is how people will come to know you and what they will type into the URL bar.  This is why you should choose a preferred domain (www or non-www) as it can have a big impact on your site should you neglect it.

Why Is ‘Preferred Domain’ So Important?

We all know that when we type into the URL bar, either;

  • www.example.com
  • example.com

… we mean the same thing.  However, search engines don’t!  There is a big difference for them whether you have a www or non-www domain, as if you don’t select a preferred one, you could be judged to have duplicate content as they will treat both as separate versions.

Think of it this way.  Some people that link to your site will use the www version, whereas some will use the non-www version.   Search engines will see these as two different sites.

This can be very bad for your site, as if you are judged to have duplicate content (even though technically you haven’t), you will be heavily penalized in the SERPs.

So, to stop this from happening on your site, you need to do 2 things;

  1. Pick a preferred domain in Google Webmaster Tools
  2. Setup a 301 Redirect (canonical URL)

How To Pick www or non-www In Google Webmaster Tools

If you haven’t already done so; you should setup Google Webmaster Tools for your site.  These are a great set of free tools that you can use to monitor the health of your site and visibility in the search engine.  Learn more in our ‘Beginners Guide To Google Webmaster Tools.

Within Webmaster Tools itself, you can select what you want your preferred domain to be.  This will tell Google which version (www or non-www) you want indexing, so that they will treat both as the same link.

To do this;

  1. Login to Webmaster Tools
  2. Select your site (or add it if you haven’t do so yet)
  3. Go to ‘Settings’ > ‘Site Settings’


On the following screen you will be able to pick your preferred domain.   It doesn’t really matter which one you pick (www or non-www), just that you pick one of them.

www or non-www

Quick Tip:  It’s a good idea to add both ‘www.example.com’ and ‘example.com’ versions of your site to Webmaster Tools.  That way, you can select the same preferred domain for each just to make sure.

Setup A 301 Redirect

Whilst we have told Google what our preferred domain is, we haven’t told any other site.  Instead of doing this manually for each search engine, we can simple add a bit of code to our site that will redirect (technically known as a 301 redirect) all of our pages from www to non-www or non-www to www, depending on what you choose to use.

Add one of the following codes (choose the right one) to your .htaccess file.  Make sure you replace ‘yoursite’ with your own domain name (i.e. onlineincometeacher).

WWW to non-WWW

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

Non-WWW to WWW

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

If, for whatever reason, these don’t work (though they should) check out this post for more codes that you can use.

There you have it.  You now have a site which, no matter whether people add www or non-www, it will automatically redirect to your preferred domain.  Make sure to test out your site, just like you can here.  Try adding www. to this post’s URL and see what happens. 🙂

Have you setup a preferred domain for your site?  Have you setup a 301 redirect for your site?  Which do you prefer, www or non-www sites?  Please let us know in the comments below!

About Matt Smith

Matt Smith is the founder and editor of OnlineIncomeTeacher. He is a Professional Blogger, SEO Consultant & Web Developer, running a number of sites from the UK. Connect with him on Twitter, Facebook, Google+ and LinkedIn.

  • Alexis Wilke

    Whether I use the www depends on several factors… one of them is whether the domain name is already quite long.

    Note also that for the Apache setup, I try to do that in the configuration files instead of .htaccess. If you can do that, it will be faster. Also, in my VirtualHost entry I make use of the ServerAlias in order for all the possible names to be understood by the same entry.

    Actually, I support 5 cases: nothing, w., ww., http://www., wwww. and the redirect goes to the official (either nothing or www.)

    • Hi Alexis,

      Yes, that’s one of the reasons why I chose to do it for this site. Any way to shorten a domain name is a good idea.

      I didn’t realise you could do this for w. ww. wwww. Nor did I realise you could do this outside of the .htaccess file. Will have to learn how to do this. Thanks for letting me know 🙂

  • Guest

    Great article! 301 redirects are indeed very important!

    • Definitely! They are something that shouldn’t be overused (redirects to redirects), but for things like this, they are very useful.

  • Clair Trebes

    Didn’t really know much about this, and this is something I think I need to sort asap for the sites I’ve got! Thanks Matt …. really easy to understand! 🙂

    • Hi Clair,

      Something that is easily overlooked on a site, but if not setup properly it can have rather big consequences.

      Mostly though, like Alexis says below, it’s for people wanting to shorten their domain name by leaving off the www bit.

  • fajarnindyo

    Basically I love to use non www at my latest blog because it reflects a straight forward url. Also I have set preferred domain at Google Console to non www.

  • Ahad Arzi

    It helped me. Thanks for sharing