To www or not to www: avoid the dupe penalty!
by Sapphire (May 6, 2005)
When your sites get indexed by the search engines, pages can be indexed with or without the “www”. It all depends whether your inbound links to those pages contain it or not.
But to the search engines, it’s two different domains, housing duplicate content. How much does that suck? And yes, people have been penalized.
Fortunately, there’s an easy solution, if your server allows you to configure an .htaccess file. (And if they don’t, I suggest finding a new host - if you’re serious about building sites, that .htaccess control is crucial.) Go to the File Manager in your Cpanel. Navigate into your public_html folder, and inside you’ll find a file called “.htaccess”. Choose “edit file” in the right-hand menu.
It’ll either have some code in it already - a lot of your php-driven software will write to that file for you - or it’ll be blank. This is the sort of file where you can just stick some code anywhere in it. I always go for the bottom, just to make sure I’m not inserting something in the middle of another application’s rules. A lot of times the apps will have “# BEGIN [app]” and “# END [app]” tags, so their stuff is set apart from the other rules.
Now that you’ve found a nice spot to put your code, here’s what you need to do. Choose whether you prefer the www or not. To my knowledge, there’s no benefit to either system, so I personally prefer no “www”. But it doesn’t matter. If you’ve submitted a gazillion links, you may want to stick with whatever format you used there.
Just change the domain name in this to yours, and pop it into the .htacess file.
Without www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^bluemushrooms\.com$
RewriteRule (.*) http://bluemushrooms.com/$1 [R=301,L]
With www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.bluemushrooms\.com$
RewriteRule (.*) http://www.bluemushrooms.com/$1 [R=301,L]
Don’t forget to leave the slash between “bluemushrooms” and “.com” in the third line! I’m not sure what it’ll do if you leave that out, but I’m pretty sure it won’t be good.
Now save your .htaccess file, and you’re done. Note that your .htaccess may already contain the line “RewriteEngine on” somewhere else. If so, you don’t need to repeat it. It won’t kill your site if you do, but it can slow down the server a bit, as you’re making it process the same command twice.


November 4th, 2007 at 11:56 pm
[...] Add www code to htaccess. [...]