root domain redirection: example.com to www.example.com

Date: 14 Jul, 2008
Posted by: admin
In: internet, web design & development|linux, open source & software|Search Engines, SEO & SEM

Bookmark and Share

I hate that .. when organisations (the biggest offenders I see appear to be the .gov.uk sites) don’t do their redirects properly.

I always just type the root domain, example.com. But for sites that I manage I choose “www.example.com” to be canonical – mainly because in print it’s best to use the www. address as it’s easy to pick out as a web address. For .com’s this isn’t as important as for .org or .net, IMO, as nowadays most people recognise that “.com” refers to a website.

UnderĀ  Apache this is easy, add this to your .htaccess file in the document root:

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

Will redirect all addresses that don’t start “www.example.com” to that same subdomain, so that includes the root domain as well as all subdomains, likeĀ  “some.example.com”.

Don’t know how this works on IIS, I’m guessing it’s hard and that’s why folks don’t do it.

FWIW

[Edit: this guy does know how it works on IIS, it is a little more involved, but not much]

2 Responses to "root domain redirection: example.com to www.example.com"


About

Flapjacktastic is just a random collection of musings, hints&tips, notes, information ... a collection of stuff really that's overflowed from the brain of this husband, father, potter, business-man, geek ...

past posts