Entrepreneur
Article
By Dan Thies

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

By Dan Thies
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

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.

Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?