Using apache’s RedirectMatch instead of ServerAlias to avoid content duplication
Most web sites I do have many domains but want all those domains to point to the “main domain” www.domain.com. My first solution was to put Apaches’s directive ServerAlias in the site’s virtual host configuration. This lead to content duplication since domain.com and domain.net and www.domain.com are two different web sites for the rest of the world. To avoid this problem the only solution I’ve found was to create two different virtual hosts and set Apache’s Redirect directive. The first VirtualHost will hold all the domains aliases and redirect permanently (301) to the “main domain”
<VirtualHost ip_address:80>
ServerName domain.com
ServerAlias domain.net
ServerAlias domain.biz
RedirectMatch permanent /(.*) http://www.domain.com/$1
</VirtualHost>
<VirtualHost ip_address:80>
ServerName www.domain.com
etc...
</VirtualHost>










Pretty cool post. I just stumbled upon your blog and wanted to say
that I have really liked reading your blog posts. Anyway
I’ll be subscribing to your blog and I hope you post again soon!
This is pretty cool, but how do you handle the same for the https:// domain.
I did try and and it looks not working. No redirection …
https needs 1 IP per virtual host. So you would have to create 2 virtual hosts listening on 2 different IPs and use the same syntax to redirect the one without www to the one with it.