1

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?

1 Answer 1

2

Apache will serve the default vhost for unknown ServerNames. Stick this at the top of your vhost config, verify with apachectl -S

<VirtualHost _default_:*>
  RedirectMatch permanent ^/?(.*) http://website2.com/$1
</VirtualHost>

http://httpd.apache.org/docs/2.0/vhosts/examples.html#default

1
  • This works beautifully, thanks! (I've reached my daily vote limit, I'll be sure to upvote it tomorow) Mar 22, 2011 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .