Although we’ve found that duplicate content rarely, if ever, results in an actual penalty against your website, there are still a number of reasons you’d want to redirect visitors to either one of the www-version or the non-www-version of your business’ website.
Before I continue, let me clarify what I mean by www vs. non-www versions; I’ll use our domain as an example. For this domain, the www-version of the URL is “http://www.razorlightmedia.com” and the non-www version is “http://razorlightmedia.com”. The only difference is that one has “www” in it and the other does not. To see it in action, visit http://rlmseo.com and watch your browser’s address bar as you’re redirected to http://www.rlmseo.com. It may happen too fast for you to see the change, but notice where you end up.
On most web servers, both the www and non-www versions are enabled by default, which means visitors can type either in the address bar of their browsers and find your site.
Now, some people will tell you that could result in a duplicate content penalty because the same page is being served through what are technically two different URLs. However, we’ve never encountered a single case of this happening on any search engines. Not to mention the fact that Google has come right out and said they don’t penalize for duplicate content – not strictly speaking at least.
So then, if not to avoid duplicate content issues, what’s the purpose of redirecting visitors to one of either the www or non-www version of your website URL? There are a few reasons, so lets get into those.
Link Juice
If you’ve spent any time reading about SEO, you probably know that a large part of what determines your rank in Google is the number and quality of links pointing to your site from other sites around the web. Although it’s nearly impossible to objectively identify the amount that each link helps you when examined individually, links pointing to both the www and non-www version of your website could spread the value of those links across the two URLs. We certainly don’t want this…we much prefer to have all of the link juice being passed to one single URL. By redirecting visitors to one or the other of the www or non-www versions of your URL using this technique, you’ll also redirect the search engines and any value they place on links to your site to the appropriate URL.
Cookies
In Yahoo’s great guide call Best Practices for Speeding up your Website, they briefly touch on a technique to avoid serving cookies with website components. The details aren’t important for the scope of this article, but one thing they mention is that when writing cookies on a non-www version of a domain you have no choice but to write to *.domain.com, which will encompass all subdomains as well. If you prefer not to have cookies written to all subdomains as well, you should use the www-version only so cookies can be set to the www domain.
User Authentication
This is a corollary of the Cookies explanation, so I’ll keep it brief. Some user authentication systems won’t recognize the user if he or she logs in via the non-www version when the system is set to accept users through the www version of the domain. Redirecting users to the appropriate version will prevent this issue.
Implementing the htaccess rules
We call these htaccess rules because they go into an htaccess file on your server. The setup is fairly simple: Create or edit the htaccess file in your document root directory and add one of the following rules to it:
Update 4/27/2010
Make sure the following line appears once before any rewrite rules in your htaccess file:
RewriteEngine On
Redirect to www
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Redirect to non-www
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
Where “domain.com” is your actual domain name.
Conclusion
While htaccess rules – as you can see – can be complicated, these rules should work on any host which has apache’s mod_rewrite enabled and allows htaccess rewrite rules.

Thanks! I’m not familiar with the .htaccess configuration, but simply wanted this to work (Redirect to www). Now it does, thanks to this article!
Was looking for a while, to find such a clear, descriptive and working solution…
One thing: I added the “RewriteEngine On” above in the further empty ‘.htaccess’ file, since I found this on several other websites…
Hi Jos, glad it helped!
That’s a good point about the “RewriteEngine On” line…I kind of assumed that would already be in the htaccess file since, when I wrote this article, it was geared toward WordPress users, but I should definitely clarify that.
Hi John,
Thanks for adding the update for “RewriteEngine On”.
I also work with several WordPress sites, where some .htaccess rules get automatically added. Yet, for some projects I work without CMS and simply need to write the .htaccess myself. All clear now. Cheers.
I just put this on my website and it worked like a charm. Thanks a bunch!
No problem Andrew, glad it helped!