I have Apache set up on a CentOS 5 box with some virtual hosts.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/default
ServerName fail
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/website1.net
ServerName website1.net
ServerAlias *.website1.net
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/website2.com
ServerName website2.com
ServerAlias *.website2.com
</VirtualHost>
Someone set up a CNAME to website2.com, effectively pretending he runs the site.
I was able to redirect it with some more Apache config magic.
<VirtualHost *:80>
ServerName evil.villain.com
RedirectMatch permanent ^/?(.*) http://website2.com/$1
</VirtualHost>
But this technique requires I specify the domain I want to redirect.
Is there a way I can just redirect all "evil" CNAME records to my own domain name?
Apache will serve the default vhost for unknown ServerNames. Stick this at the top of your vhost config, verify with
apachectl -S
http://httpd.apache.org/docs/2.0/vhosts/examples.html#default