Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 *:80>
  DocumentRoot /var/www/html/website1.net
  ServerName website1.net
  ServerAlias *.website1.net

<VirtualHost *:80>
  DocumentRoot /var/www/html/website2.com
  ServerName website2.com
  ServerAlias *.website2.com

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

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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


share|improve this answer
This works beautifully, thanks! (I've reached my daily vote limit, I'll be sure to upvote it tomorow) –  Kenny Rasschaert Mar 22 '11 at 11:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.