views:

414

answers:

1

I have a virtual host setup on Apache 2 like so (simplified):

<VirtualHost *>
  ServerName domain.com
  ServerAlias *.domain.com
  DocumentRoot /var/www/domain.com/html
</VirtualHost>

<VirtualHost sub1.domain.com>
  ServerName sub1.domain.com
  DocumentRoot /var/www/sub1.domain.com/html
</VirtualHost>

<VirtualHost sub2.domain.com>
  ServerName sub2.domain.com
  DocumentRoot /var/www/sub2.domain.com/html
</VirtualHost>

The outcome I'm looking for is everything that isn't sub2.domain.com or sub1.domain.com should go to the domain.com. They all have to be on the same default port and they all share the same IP address.

What actually happens is that sub2 goes to sub2 as expected, and everything else goes to sub1, i.e. the wildcard definition is ignored.

How can I fix this up?

Thanks!

A: 

Change the <VirtualHost sub1.domain.com> to <VirtualHost *> and <VirtualHost sub2.domain.com> to <VirtualHost *> also. First one is the default one anyway.

Nguyen Nguyen
Almost perfect! I also had to remove ServerAlias *.domain.com from the top VHost too (which is what you may have meant by "First one is the default one anyway"). Thanks!
majelbstoat