Nate Whitehill dot Com is now running on ColorMatic Theme. Get ColorMatic Theme Today!

Have You Set Your Preferred Domain?

Posted on April 11, 2007 by Nate Whitehill

Have You Set Your Preferred Domain?

All web sites can be reached from two URL addresses: one with the WWW and the other without the WWW. For example, you can reach this blog by typing in http://www.natewhitehill.com and also http://natewhitehill.com.

However, it is imperative that you pick one address and stick with it for maximum search engine results and PageRank. If, generally, you use the version with the WWW and someone links to your site and they do not include the WWW, the search engine spiders will index that link as a separate domain from the one with the WWW.

For example, my good buddy, Matt from Take More Risks, recently had 2 separate PageRanks for his blog. His blog URL with the WWW had a PR 3, while the URL without the WWW had a PR 2. In other words, Google indexed that same domain as 2 separate ones. Most likely, he could have achieved a higher PageRank if he had set his preferred domain earlier. If you don’t quite understand PageRank, read this article about the upcoming PageRank update.

Which Preferred Domain Should You Choose?

Well, first you need to pick which version you rather use. I chose to go without the WWW, so my preferred domain is http://natewhitehill.com. There is no one reason to pick one instead of the other – it is purely a matter of preference. I chose to go without the WWW because having a longer domain name (13 characters, in my case), I thought it would make it easier for people to remember the URL if they just saw the natewhitehill.com and not the www.natewhitehill.com. John Chow, on the other hand, chose to use the WWW. Just to reiterate, there is no definitive reason to pick one over the other.

Setting the Preferred Domain

After you choose your preferred domain, you must now create a 301 Redirect to forward one address to the other. If you are hosted on a Linux server, you do this by editing your .htaccess file. You may first need to create one and to do this you must:

1) Create a simple text file and name it .htaccess
2) Modify it with the proper code (details below)
3) Upload it to the root of your server

Here is the code you should use if you want people to redirect from non-WWW to WWW:
(for example, if someone types in http://domain.com, it will forward to http://www.domain.com)

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

Here is the code you should use if you want people to redirect from WWW to non-WWW:
(for example, if someone types in http://www.domain.com, it will forward to http://domain.com)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^.*$ http://domain.com%{REQUEST_URI} [R=301,L]

In both cases, make sure to replace “domain” with the URL of your domain.

By setting a preferred domain you are ensuring that Google and all the major search engines will only index links from one domain. This will help your PageRank the next time around and also you receive more weight in current search engine rankings.

If you have not set your preferred domain yet or have been putting it off, DO IT NOW. You will thank me later when you get a higher PageRank.

42 Responses to “Have You Set Your Preferred Domain?”

  1. Bri

    - 11th Apr, 07 05:04am

    Done! Thanks for the heads-up, Nate. I appreciate the sound advice.

  2. Frank

    - 11th Apr, 07 05:04am

    I’ve been thinking about this for a while but your post has spurred me into action. I’ve now set it on the server and then gone into Google Webmaster tools and set the preference to the same. Hopefully they won’t penalize me for changing this right before a PR update. Cheers.

  3. Ryan J. Parker

    - 11th Apr, 07 06:04am

    Why yes, yes I have. I always use WWW. I have WordPress-MU setup on one website, and it doesn’t work well with WWW, so that’s the only one that isn’t WWW.

  4. Ryan McDonnell

    - 11th Apr, 07 08:04am

    The same thing also applies to the default page for a site. The root, “/”, and “/index.php” or “/default.aspx” are considered unique URLs in the search engines. A similar rewrite rule can be added to 301 redirect all requests for the default document to the root of that folder.

    I covered how to do this with a WordPress blog a little while back on my blog:
    http://www.ryanmcdonnell.com/redirect-indexphp-to-with-wordpress/

    The rule looks something like this:

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
    RewriteRule . / [R=301,L]

  5. Jane May

    - 11th Apr, 07 09:04am

    Great piece of advice. I did this 2 months ago when I realized I was able to do so.

  6. Scot Smith

    - 11th Apr, 07 11:04am

    Good advice. Done this a while back actually.

  7. Natron

    - 11th Apr, 07 01:04pm

    Very good suggestion. I use this type of code on all of my content sites also.

  8. mike

    - 11th Apr, 07 03:04pm

    You would expect that since www and non-www sites display the same, a search engine would be able to know that. I can’t think of any time when http://www.example.com and example.com would ever be different.

  9. Nate Whitehill (author comment)

    - 11th Apr, 07 03:04pm

    Hey Ryan – great tip! Thanks for bringing this up! :)

  10. Frank

    - 11th Apr, 07 03:04pm

    Funny you should say that. Ja Kel has this very setup with his wife’s blog. It’s pretty unusual but it seems to work for them.

    http://jakeldaily.com/two-blogs-one-domain-double-power/

  11. Shane

    - 11th Apr, 07 04:04pm

    Nate,

    I notice that if I put www in front of this posts url … it redirects to your homepage … hmm. Wouldn’t it be better to redirect to the same address without the www? Not that I have a clue if it’s better or how you would do it … just some fuel for the discussion here

  12. Nate Whitehill (author comment)

    - 11th Apr, 07 05:04pm

    Hey Shane, yeah I just noticed that. Frankly, I have no idea how to fix it so that if someone does have the full post URL and types it WWW it redirects to the post without the WWW. Thankfully, most people will copy and paste a post URL instead of typing it out long hand. Interesting point, however.

  13. Shane

    - 11th Apr, 07 07:04pm

    I’m just thinking that if you link to your own posts or other people have links to certain posts using www, and you change your preferred domain to non-www, those links are now wrong.

    And it’s only a problem if you change this mid-stream in a site’s life after some links have been established.

    Guess I’ll look into it a bit more and make a decision,
    thanks Nate

  14. Nate Whitehill (author comment)

    - 11th Apr, 07 07:04pm

    You are correct that if I change my site back to WWW the links will be dead. I guess I’ll just have to stick with non-WWW for my lifespan. Let me know if you find a way around the redirect for the individual posts.

  15. Natron

    - 12th Apr, 07 06:04am

    A 301 redirect will direct all the weight of the backlink to the target domain. Although there may be a time lapse before the weight is transfered, it will transfer. This not only works within a site, but also if you switch domains. Think of it as forwarding your mail to your new apartment.

    Forget about adding code to your .htacces and install this simple plugin: http://txfx.net/code/wordpress/enforce-www-preference/

  16. Ryan McDonnell

    - 12th Apr, 07 10:04am

    Can you post the contents of your .htaccess file? I’m thinking there might another rule that is causing this behavior. I’m using the same rule and individual posts are being redirected properly.

    My .htaccess looks like this:

    Options +FollowSymLinks

    # Redirect @ to www

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

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
    RewriteRule . / [R=301,L]

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

  17. Natron

    - 12th Apr, 07 10:04am

    This may help, a little different…

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

  18. Nate Whitehill (author comment)

    - 12th Apr, 07 05:04pm

    Thanks for the code, Ryan. That is very helpful.

  19. Nate Whitehill (author comment)

    - 12th Apr, 07 05:04pm

    Thanks for the heads up on the plugin, that will simply things quite a bit for those not so technically savvy.

  20. Natron

    - 13th Apr, 07 06:04am

    best bet not to mess with .htaccess especially when the program is writing to it.

  21. Shane

    - 13th Apr, 07 09:04pm

    Natron,

    Awesome.

    I try to keep plugins to a minimum, but I don’t know too much about .htaccess. I tried both your code and the plugin. They both work perfectly so I’m going to go with the plugin so I don’t overwrite the code accidentally.

    And thanks for starting the discussion Nate!

  22. TeamTutorials

    - 18th Apr, 07 04:04pm

    I always wondered if there was any logic behind dropping the www.

  23. Natron

    - 19th Apr, 07 08:04am

    I would think that appending the “www” would be the best bet as most will link with the “www” added anyway, you have less links to 301 redirect. I hope Nate responds with his reasoning.

  24. coop

    - 19th Apr, 07 01:04pm

    this rocks.

  25. coop

    - 19th Apr, 07 01:04pm

    will this work if i do a mod rewrite to foward all digg traffic to a mirror?

  26. Nate Whitehill (author comment)

    - 19th Apr, 07 05:04pm

    301 redirects work for directing any URL to any oher URL.

  27. Nate Whitehill (author comment)

    - 19th Apr, 07 05:04pm

    Only reason I got rid ot the WWW was so that it would be easier for people to visually remember my name from looking at the URL without all the WWW’s.

  28. Natron

    - 8th May, 07 01:05pm

    I prefer the fully qualified domain with the “www” as many editors will associate that as a link. That will be the only real reason I see.

  29. derek

    - 27th Jun, 07 04:06am

    Curious if my domain is in a subdirectory, for instance I have a blog installed in a blog folder like http://www.mydomain.com/blog do I have to change the htaccess file to see the subdirectory or is it fine as is?

  30. Natron

    - 27th Jun, 07 08:06am

    You would need to place a .htaccess file in the root to redirect any traffic to the subdirectory. In the subdirectory you would also need a directive as given to append the “www”

  31. nsderek

    - 28th Jun, 07 09:06pm

    Thanks thought I am not exactly sure what you mean by in the subidrectory you would also need a directive as given to append the wwww.

    Are you saying that I need to add the same code to another htaccess file in the subdirectory as well? Forgive my rookieness

  32. nsderek

    - 29th Jun, 07 08:06pm

    Damn I wish I read all the comments earlier. That plugin works great for redirecting and that would work just as good as manual. Still like to know how to get it to work manually. I tried it but it would only redirect my main page in the root, anything that was in my subdirectory wouldnt do anything

  33. S

    - 15th Jun, 08 09:06pm

    The problem persists. I writed down code you proposed and uploaded it to the server with *.txt format. however, now, when trying to reach my site with WWW, 404 error accures… What shall I do?

  34. Greg

    - 21st Nov, 08 07:11am

    Exactly the info I needed and in plain English. Thanks!

  35. DC Internet Consultant

    - 30th Apr, 09 03:04am

    Once again, I forgot to set the preferred domain. I entered my website into the WebsiteGrader and got a terrible ranking. Since then, I have been using ShoeMoney Tools plus other resources to improve my overall SEO portfolio. Thanks for the great post, Nate. I have to search Google and grab the code for every site I start! LOL

  36. lance

    - 10th Jun, 09 05:06pm

    Is this code or file will work on my static site?

Squeeze Theme
© 2007 Nate Whitehill dot Com. All rights reserved. ColorMatic Theme by Theme Wars.