Setting The Preferred Domain

Most websites can be reached with two addresses. One address has the www in it, like, while the other address has the www missing;

From a SEO standpoint, it is better to pick one domain format and stick with it. This way you don’t have Google giving separate PageRank for two URLs that point to the same page. The easiest way to do this is by logging into your Google Webmaster Tools account and setting a preferred domain.

The preferred domain is the one that you would liked used to index your site’s pages (sometimes this is referred to as the canonical domain). Links may point to your site using both the www and non-www versions of the URL (for instance, and The preferred domain is the version that you want used for your site in the search results.

Once you tell us your preferred domain name, it may help us determine PageRank for your site more accurately.

Adding a 301 Redirect

After you set the preferred domain, you should force everyone to use this domain with a 301 redirect. You do this by editing your root .htaccess file. I want everyone visiting John Chow dot Com to do so with the www in the URL. To force this, I open my .htaccess file and enter the following codes:

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

You will need to replace with your site URL. What the above does is redirect all to How does this help with search ranking?

By maintaining one preferred domain format, you ensure linking consistency. If you have 10 sites linking to your article with a www and another 10 sites linking without the www, you present Google with two pages, which will not receive the same weight as 20 sites linking to the preferred domain. The above .htaccess code will ensure that everything goes to the domain format you want.

Note – the .htaccess redirect works only on Linux servers with the Apache Mod-Rewrite module enabled.

53 thoughts on “Setting The Preferred Domain”

  1. Jane says:

    Good information especially for those trying to get ranked by Google (should be everyone!). The only bad news is I don’t have the Linux servers ๐Ÿ™

    1. Matthew says:

      This can be done in Windows a few ways.

      1st by installing a rewrite DLL (can be pricey or free with restrictions to X amount of page loads or something.


      2nd Coding it in to the header of your pages to switch the page to the www version (not sure if thats a 301 or 302 though. I have never tested this way).

      3rd Opening up IIS and creating 2 websites ( and and then setting 1 to redirect to the other by specifying a permanent redirection for this resource.

      With all 3 of these there might be something custom to write… but with rewrite on NIX you also need to manually write the rules too, so either way there is work to do.

      1. Jane says:

        SAWEEEEET! I’ll look into it. Thanks for the info Matthew!!! I’ll let you know how it turned out.

  2. That’s a very useful piece of information – thank you, John. It’s something I was wondering about in the back of my mind, but it never surfaced for an investigation ๐Ÿ™‚

  3. Nate W. says:

    Very useful tip. I have been using, because I think the www adds too much typing to my direct address. Is there a particular reason you prefer using the www, John? Or is it simply a matter of preference?

    1. John Chow says:

      It’s more preference than anything else. I feel an URL should have www because it tells this URL points to the World Wide Web. There are other prefaces we can put in front of our domain that would mean something else. Like or I want make sure they go to ๐Ÿ™‚

  4. Cory OBrien says:

    I prefer the www just because I feel like that is what most people would type if they were to type in your address.

    1. Jane says:

      I agree. I jut think that the majority of people that are using the internet have come to know it as the “world wide web.” It’s second nature to put www. in front of any domain.

    2. Kalle says:

      Do you think? I have the opposite opinion. It is much more easy to write than, and I think most of the internet users write without www.

  5. Leftblank says:

    Nice tutorial, I’ve been using it for a while already though. A little note; that .htaccess works like a champ on Apache on Windows or OS/2 or so as well, it’s not depending on Linux as platform ๐Ÿ˜‰

  6. Allen.H says:

    Nice tip John, since there’s a bit of controversy on whether with/out the www is better I’ve doing a test for 2 months now…although I think there is no (significant) difference between the two SEO-wise.


    1. Jeff says:

      Until the debate of which is better is settled.. we may as well set it to just one of them for consistency.

  7. goddoll says:

    Ok, so I’m guessing that explains why there are a couple different sites on technorati’s top 100 twice?

  8. Chris says:

    My understanding of it is that that without WWW is the correct form, and the true URL of your site.

    The WWW is unnecessary.

    Just being contrary John? ๐Ÿ˜‰

    1. Matthew says:

      Technically yes “” it is the correct form. When you buy a domain you do not buy You buy WWW is just an alias with an A record in DNS. You might notice some larger sites have and indicating possibly a different server for a simple load balancing solution.

      WWW has caught on though over the years and a number of people I know always enter www before a domain name. Some even get a bit confused when I tell them a domain name over the phone without www. They always ask if they need to add www to the front of that.

      At the end of the day I dont think it really matters which you specify as long as you stick with 1 format or the other on your site and 301 any other possibilities to the 1 format… be it a www record or second domain.

  9. Tam Denholm says:

    You can also use PHP to do it. Personally i think domains look neater with the www subdomain. Its also very easy to do it with wordpress. At the top of your index.php file just add this:

    if(!strstr($_SERVER['HTTP_HOST'], 'www')){

    What it does is check for the a www in the address requested and if it doesnt exist it forwards you to the address with the subdomain. Similarly you could do the same if you wanted to not include the www:

    if(strstr($_SERVER['HTTP_HOST'], 'www')){

    You could also extend that to add the pages and query strings aswell.

    1. Martin says:

      Thanks for the comment. It works great.

      I did the non-WWW version.

    2. Aris says:

      This one works fine. First, I forgot the php brackets and the code appeared on top of the page. Once I added the code, it works fine for both Fairfox and IE. Thanks.

      1. Aris says:

        Oops, Houston, we have a problem. ๐Ÿ™‚

        After adding the code to add ‘www’ to the URL, now, when I click to read “More”, it didn’t bring up the whole posting.

        Any suggestion? Which php file do I need to edit?


  10. Ryan says:

    If Google allows you to set the preferred name then why aren’t they giving the same weight to the pages? I tell Google they’re the same, so why are they then treating them differently?!

  11. Marc says:

    This is some of the best advice you can give to new webmasters. It’s a common issue that’s very easily resolved.

    Be sure to set up the redirect though. While the Google Webmaster Tools setting is helpful, it will only work for Google, so don’t skip part two.

  12. Good tip John but do you think it actually makes much difference?

    1. Allen.H says:

      Of course it does! John explains it the best here:

      “If you have 10 sites linking to your article with a www and another 10 sites linking without the www, you present Google with two pages, which will not receive the same weight as 20 sites linking to the preferred domain.”

      Now that’s a massive difference in the long run!


  13. Like this tip a lot John. It’s been something that has started to bug me in recent times as people either have badly configured their apache rewrites or worse still. Entering the gives one site and gives another. There have been countless cases when I’ve had to point people in this direction – let’s hope they’re reading your blog now! ๐Ÿ™‚

  14. Al Davies says:

    Definitely make sure to back up your .hta before making any changes to it. You might want to back up your blog db also while you’re at it.

    1. Nomar says:

      Yes, I made the mistake to, when i first experimented with .htaccess

  15. Kenny says:

    Good write-up. I wrote about the exact same topic just prior to you posting it up so hopefully readers that stumble on my blog don’t think that I am stealing content ๐Ÿ˜‰

  16. Patrix says:

    Thanks for this tip, John. I was looking for a quickfix solution. It worked like a charm.

  17. Wicked good info.

    Always appreciated.


  18. dangerou says:

    John – can you post the code to do the same thing in the other direction? (To make it exclude the www)

    1. Nate W. says:

      I also would this… can anyone else please try rewriting it for us? Thanks!

    2. Kenny says:

      The following code will do it backwards and will drop the www from the domain name:

      RewriteCond %{HTTP_HOST} ^www\.davidsmalley\.com$ [NC] RewriteRule ^.*${REQUEST_URI} [R=301,L]

    3. Kenny says:

      Oops, forgot to add, you’ll have to change the domain name from the person I found the code from to your own domain name.

      1. Nate W. says:

        Thanks for the help, Kenny! It works like a charm!

  19. Yes, good tip, John. I found that dreamhost also allowed me to do that! So I set it up like that, otherwise I wouldn’t have realized. Some of my websites have two different PRs. If I added them together, some of my websites would have a PR6. Unfortunately, I don’t think PR is quite that simple!

    1. Actually, the PHP code tip was excellent. I will ad that to my website soon. Just hope I can hack the php on my blog without screwing up the blog completely.

  20. Nomar says:

    I already did that with .htaccess

    but I am also going to set it in google.. thanks for the extra info

  21. uncle sha says:

    I never thought about this, thanks for the tip, great one!

    I’ve set it up easily on my server … cool!

  22. TJP says:

    I noticed a couple of my links were showing up w/o the www, but didn’t know how to fix it. Thanks for the info.

  23. Aris says:

    Since I have trouble in reading the ‘more’ part after forcing the URL to add ‘www’ using Tam Denholm’s code shown above, I have reverted it back to Tam’s ‘no www’ code and so far it works fine. I think I should keep it without ‘www’. At least, last night when I changed the URI by adding ‘www’ in my comment here, it didn’t go through. My guess was, I have used no www in my URI so far and adding www to my URI means a new URI to this blog.

  24. Max says:

    Does Technorati have a way of picking up both the www domain and the one without the www? What about Alexa?

    1. Jeff says:

      good question. anybody know the answer? i’d like to find out.

  25. Thanks for this tip as well john, I will have to try this and the favicon thing, and still try to work in some of the pluggins i havnt had a chance to add.

  26. Ryan says:

    If you’re running WordPress butyou aren’t using Apache and/or don’t want to edit .htaccess, then there is a plugin that will redirect for you.

    It’s called WWW Redirect and can be found at:

  27. ketyung says:

    Nice tip john, I’m wondering if this affects the pr ? I have a PR4 for w/o www, but getting only PR2 with www, I’ve done for the .htaccess and now access using w/o www will be forwarded to the one www. Will this method balance up my PR or make it drop to 2?

  28. Kalle says:

    Thanks for the great information ๐Ÿ™‚

  29. Robert says:

    For WordPress, there is also the Enforce plugin. Enforcers whatever you set for your domain under General Options.

    Works perfectly with WP 2.1.

  30. Lailani says:

    Thanks John for the great free ebook I got from PotPieGirl…

    This is how green I am so please bare with me…

    How do/Where do I access the .htaccess file?

Comments are closed.