One of the first things I do after launching a new site is make sure every page is unique as far as the URL is concerned. By this I mean that IMHO you should not be able to view this page:
http://some-site.com/articles/12
As well as this page:
http://www.some-site.com/articles/12
One should forward to the other, or vice-versa.
How come?
Once-upon-a-time, allowing this could throw off your Google Page Rank. While this isn’t the end of the world, why have http://www.some-site.com be a PR5 and http://some-site.com be a PR3? (This happens when some people link to one or the other.) By forcing the “www.” on or off of a domain, you could easily remedy this issue. I think Google has tweaked their algorithms to where this doesn’t really matter much anymore, but for me, I just think it’s cool and a sign of great attention to detail to have one or the other.
Anyways, to always force the “www.” onto your domain, add this to your .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And to strip it off, you might try something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.your-domain\.com [NC]
RewriteRule ^(.*)$ http://your-domain.com/$1 [L,R=301]
Note that the above example “hard-codes” the domain into the rewrite rule. It’s not as slick as the previous example (which you can just cut/paste into any website’s htaccess file), but it should work.
Blogging Gotch-ya’s
Some blogging software makes the above obsolete. For example, in WordPress you can set up your “WordPress address” in the Options section. Now, if you use the above code to strip off the “www” from your domain in htaccess, but in WordPress you set up your domain with the “www” in your “WordPress address” - you’ll get an endless loop that’ll either crash the browser or result in some sort of error.
Does it matter?
These days, I think it boils down to personal preference. Once upon a time, yes, it did matter - the “www” (which of course stands for world wide web) is actually a subdomain call. It used to be needed in order to direct internet traffic from non-internet traffic, such as “ftp.domain.com.” Of course, we’ve moved passed this. There are some people who feel very strongly about dropping the “www” from all websites. I think these folks have a bit too much time on their hands.
The bottom line is as long as your website works for both the www and non-www version, you’re OK. If your website only works on one of these, then it’s time to worry (I run across this with Microsoft’s IIS servers, which I loathe to the point of never ever touching again). The rest are merely style-points.
Leave a comment