I am trying to configure apache2 to have the following virtualhosts:

  • One that serves requests for www.mydomain.com
  • Another one that servers requests for anything else

How do I go about doing this?

link|improve this question

67% accept rate
feedback

1 Answer

up vote 2 down vote accepted
  1. Have a NameVirtualHost *:80 directive, and define both VirtualHost blocks as <VirtualHost *:80>
  2. Put your "anything else" vhost first in the config (or alphabetically first in an included directory) with any ol' ServerName - it'll get all requests that don't match the other host - and your vhost with ServerName www.mydomain.com second.

That's all!

link|improve this answer
I've done what you said, but the anything else vhost is getting requests for www.mydomain.com. – DanieL Nov 18 '11 at 3:36
Are you sure the vhosts match the NameVirtualHost exactly? Please post your config. – Shane Madden Nov 18 '11 at 3:37
pastebin.com/iG6Sr6fy. I'm trying to redirect anything that is not for mydomain.com to mydomain.com. – DanieL Nov 18 '11 at 3:41
1  
Hrm - not 100% sure if this is required (I've never tried without one), but try adding ServerName something.something.something to your 000-default vhost. – Shane Madden Nov 18 '11 at 3:54
Straight from the Apache documentation: If you are using name-based virtual hosts, the ServerName inside a <VirtualHost> section specifies what hostname must appear in the request's Host: header to match this virtual host. – gman Nov 18 '11 at 5:09
show 7 more comments
feedback

Your Answer

 
or
required, but never shown

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