Wednesday, 5 August 2009

Catch-all redirect in Apache

Assume you have a website running on an Apache server and the URL is What if you want to dominate the UK market too!? You'd probably buy and point it to the same server. This is bad! It causes something called Canonicalization - web content that has more than one possible URL. This can lead to massive SEO penalties so my advice is avoid it at all costs.

Instead, have a single URL that serves the content and defer anything else. In this scenario, would be the master and the rest (e.g. would return a 301 redirect (not a 302). It's also worth mentioning that and are different (with and without the "www." prefix). If they both serve the same content, Canonicalization will occur. Choose one and stick with it.

The following can be put inside the httpd.conf file to allow a single URL access to a website and redirect the others:

<VirtualHost *:80>
DocumentRoot /var/www

<VirtualHost *:80>
ServerName default
ServerAlias *
Redirect 301 /

I'll also do a follow-up post to show how to do the same in IIS.

No comments: