example.com vs. www.example.com… trouble!

Dan Thies

If you had the SitePoint SEM Kit you’d already know about this, but since some folks haven’t actually bought it yet, here’s something important you should know.

Most web servers (therefore most web sites) are configured to show the same content whether visitors request a page with or without the www in the address. So h t t p : / /example.com is likely to give you the same content as h t t p : / / www.example.com.

If your website does this, that’s not good, because you are showing the same content to the search engines under more than one URL. In other words, your site is serving up duplicate content.

Now, some folks hear “duplicate content” and assume that there’s some kind of penalty involved, but that’s not really the problem. The problem is that search engines have to choose *one* of those copies, and declare it to be the official “canonical” URL. If you’ve put all of your effort into promoting www.example.com, you’d hope that the search engines would see that as the canonical version… but will they?

Maybe, but if God doesn’t play dice with the Universe, you definitely shouldn’t play dice with the search engines. Especially when a post at Threadwatch, the official blog of search engine spammers*, is talking about how to take advantage of your little mistake to sabotage your rankings.

The right solution is to pick one version (I like the www. version myself) and redirect the other version to it, with a 301 Permanent redirect. There are many ways to accomplish this, on most Apache setups it’s as simple as using your .htaccess file.

Example 1, .htacces entry to redirect anything.example.com (and example.com itself) to www.example.com:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Example 2, to redirect anything.example.com (except for subdomain1.example.com and subdomain2.example.com) to www.example.com:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www|subdomain1|subdomain2.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

This code is provided for entertainment purposes only, use at your own risk, yadda yadda.

*Hi, Nick, just trying to boost your rankings for a targeted search term.