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:

NameVirtualHost 1.2.3.4:80

<VirtualHost 1.2.3.4:80>
 ServerAlias *.mydomain.com
 DocumentRoot /var/www/old
</VirtualHost>

<VirtualHost 1.2.3.4:80>
 ServerName mydomain.com
 ServerAlias www.mydomain.com
 DocumentRoot /var/www
</VirtualHost>

<VirtualHost 1.2.3.4:80>
 ServerAlias dev.mydomain.com
 DocumentRoot /var/www/dev
</VirtualHost>

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.