I've the domain, we'll refer to it as "mydomain.com" and that i want the next virtual hosts established to resolve within the following way:

  • mydomain.com / www.mydomain.com to suggest to /var/www/
  • dev.mydomain.com to suggest to /var/www/dev/
  • *.mydomain.com (all other subdomains) to suggest to /var/www/old

My apache configuration is presently setup as:


 ServerAlias *.mydomain.com
 DocumentRoot /var/www/old

 ServerName mydomain.com
 ServerAlias www.mydomain.com
 DocumentRoot /var/www

 ServerAlias dev.mydomain.com
 DocumentRoot /var/www/dev

Regrettably, this isn't being employed as I was expecting. With this particular configuration, just the first (wildcard) VirtualHost entry works correctly.

What's the proper way to configure Apache to get this done?

Put the wildcard entry last within the file. Apache uses the very first VirtualHost that suits the Host header being sent through the browser.