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 188.8.131.52:80 <VirtualHost 184.108.40.206:80> ServerAlias *.mydomain.com DocumentRoot /var/www/old </VirtualHost> <VirtualHost 220.127.116.11:80> ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /var/www </VirtualHost> <VirtualHost 18.104.22.168: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.