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

Share

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’

Google-Webmaster-Tools-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.