Using name-based virtual hosts in Apache, you can do this:
<VirtualHost *:80> ServerName example.com ServerAlias wwww.example.com www.www.example.com [space seperated list] Redirect / http://www.example.com/ </VirtualHost>
The redirect can take a parameter to indicate the type of redirection.
Cogsy source share