I'm trying to learn about setting up httpd.conf and httpd-vhosts.conf files. I would like to have a local setup, using Wampserver on Windows 7, so that I can add a new project just by adding a new directory and a quick edit to the hosts file. I would like for it to work at least for the following general domain formats: domain.com, www.domain.com, sub.domain.com, and www.sub.domain.com.
The following is what I have so far. It seems to work, but I'm just thinking there is likely a better, possibly more succinct way:
NameVirtualHost *:80
<Directory "C:/wamp/www/%0/public_HTML">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
VirtualDocumentRoot "C:/wamp/www/%0/public_HTML"
</VirtualHost>
<VirtualHost *:80>
ServerAlias www.*.*.com
VirtualDocumentRoot "C:/wamp/www/%3+/public_HTML/%2"
</VirtualHost>
<VirtualHost *:80>
ServerAlias www.*.com
VirtualDocumentRoot "C:/wamp/www/%2+/public_HTML"
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.*.com
VirtualDocumentRoot "C:/wamp/www/%2+/public_HTML/%1"
</VirtualHost>
My folder structure is as follows: C:/wamp/www/(project)/public_HTML/(folder named as the sub part of sub.domain.com)
This works, but if I change the order of the VirtualHosts in any way, it causes a 404 error for at least one of the domain formats listed above. I was wondering if anyone could explain to me why that is? And also, if someone has a suggestion for a better way, I'd love to hear it.
Thanks!