Not long ago, I was looking information on how to create and configure an Apache sub-domain on my test server. I found a number of websites covering the subject, but even after editing my httpd.conf file to add the domain and sub-domain entries, the sub-domain would not work!? So I did more digging and testing and what I found was that the various tutorials and explanations all omitted one crucial element to the puzzle, none of them mentioned that you had to also add a subdomain entry to Windows’ host file! I assumed that since the domain already had an entry, Apache & Windows were smart enough to know that a sub-domain would use the same host entry as the domain, I was wrong! Apparently, Apache & Windows are not that smart, actually they appear to be blatantly stupid!
So the first thing you have to do is edit the httpd.conf file to add the required virtual host entries: 1 for the domain & 1 for the sub-domain
ServerName www.domain.com
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/websites/www.domain.com"
ServerName subdomain.domain.com
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/websites/www.domain.com/subdomainFolderName"
But even once this is done, you then have to go and make an entry for both your domain and another for your sub-domain in the Windows Host file. The values below assume a local test server
127.0.0.1 www.domain.com
127.0.0.1 subdomain.domain.com
Once you make both of these changes, restart your Apache server, and everything should work. It did for me at least!
