What Virtual Host Definitions do I need to support subdomain.mydomain.com and *.mydomain.com on the same IP Address on Apache 2?

StackOverflow https://stackoverflow.com/questions/300976

Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top