14 Jul, 2008
root domain redirection: example.com to www.example.com
Posted by: admin In: SEO / SEM| admin| linux| web development
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]




visitors said ...