Have You Set Your Preferred Domain?

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.

43 thoughts on “Have You Set Your Preferred Domain?”

  1. 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.

  2. 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.

  3. 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:

    The rule looks something like this:

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

  4. 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

    1. 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.

  5. 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

    1. 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.

      1. 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

    2. 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/

      1. Natron,


        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!

    1. 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.

        1. 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.

    1. 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”

  6. 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

  7. 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

  8. 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?

  9. 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

  10. Great tip, thanks – note that if you use WordPress the rewrite rule may already be set, so probably best not to do it twice : ) .. just look in the htaccess and you will see.

Comments are closed.