For example, all of the following are likely to point to the same page:
- http://samplesite.com
- http://www.samplesite.com
- http://samplesite.com/index.html
- http://www.samplesite.com/index.html
If other websites link to yours inconsistently (which will happen sooner or later), different versions of the same pages can get indexed in search engines. This forces the search engines to choose the best URL to rank. Your PageRank will be diluted by the fact that some links are going to different URLs for your page.
Do you have this problem? It’s easy to check. In your browser, navigate to www.yoursite.com (substituting your own domain, of course). Then go to yoursite.com (without the “www.”). If both go to the exact same URL (check the address box in your browser), then you’re in good shape. But if one displays your URL with the “www” and the other displays it without, then you have this problem.
How to Fix This
To use the with-www version of your site, use this code, substituting your domain as appropriate:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
To use the without-www version of your site, use this (again substituting as appropriate):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yoursite.com
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
That’s it! Just test to make sure it works.
Of course, you still need to make sure all the sites linking to yours are linking to the right version, and that if they’re linking to your home page they’re not including the actual page filename after the .com. But this little trick should take care of the worst of things.
[Update — Be sure to employ the same 3 lines of code when you migrate your site from an insecure “http://” prefix to a secure “https://” prefix.]