Maybe it’s just me, but I get kind of annoyed when websites are accessible by both their non-www and www URL. If you attempt to go to my site by using, you’ll see that you’re automatically sent to instead.

Why should you do this?

If you require people to login to your site, you probably give them a cookie so they don’t have to login each time. But that cookie is only good for one or the other URL, not both. So if somebody logs in using and comes back later using, they’ll be forced to login again, even though a cookie already exists for them using the other version.

Also, forcing one URL variety over the other ensures that you won’t be double indexed or receive split page ranks in the search engines. While Google does a pretty good job on their end of preventing this, it’s possible that you could have two distinct page rank values for each version of the web page, even though they are 100% identical in content, but only differing in the presence of “www” in the URL.

How do you do it?

It’s simple really. Just add the following code to your .htaccess file in the highest folder of your web directory and yor visitors will be forced to use the www version.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]