Windows – Apache setup virtual hosts for multiple urls

apache-2.2virtualhostwindows

I have the Bitnami Wampstack installed running 2 different websites, each with two different URLs. The virtual hosts are set up as follows:

NameVirtualHost *:83
NameVirtualHost www.first.co.za:83
NameVirtualHost www.first.net:83

<VirtualHost www.first.co.za:83>
  ServerName www.first.co.za:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla2"
</VirtualHost>

<VirtualHost www.second.net:83>
  ServerName *:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla"
</VirtualHost>

<VirtualHost www.second.co.za:83>
  ServerName www.second.co.za:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla"
</VirtualHost>

<VirtualHost www.first.net:83>
  ServerName www.first.net:83
  DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla2"
</VirtualHost>

Three of the URLs redirect correctly, but the fourth, www.first.co.za, displays the website for www.second.net, which seems to be default. What is wrong with my configuration?

Best Answer

Since you only really have two sites, I'd recommend to only set up two virtual hosts and do the rest with aliases, like this:

NameVirtualHost *:83

<VirtualHost *:83>
ServerName www.first.net
ServerAlias www.first.co.za
DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla2"
</VirtualHost>

<VirtualHost *:83>
ServerName www.second.net
ServerAlias www.second.co.za
ServerAlias *
DocumentRoot "C:/Program Files/BitNami WAMPStack/apache2/htdocs/joomla"
</VirtualHost>

This removes the redundancies and makes for clearer reading, plus it's easier to maintain.