I’m trying to set up a subdomain on localhost so that blog.localhost resolves to localhost/blog. I need this as it affects the PHP code as this is how the server is set up on my main server (this is just a dev server).
At the moment i have the following at the end of my httpd.conf file.
<VirtualHost blog.localhost>
DocumentRoot "c:/dev/blog"
ServerName blog.localhost
</VirtualHost>
<VirtualHost localhost>
DocumentRoot "c:/dev"
ServerName localhost
</VirtualHost>
This works and blog.localhost shows localhost/blog, unfortunately localhost also shows localhost/blog. If I swap these two virtualhosts around the opposite happens!! It appears as though the first VirtualHost takes preference. If I remove the ‘localhost’ VirtualHost then localhost again just shows localhost/blog.
My hosts file looks like the following
127.0.0.1 localhost
127.0.0.1 blog.localhost
OS: Windows XP Pro
Server: Apache 2.2.2
If someone could shed some light on this issue I would sooooooo appreciate it.
Also is it possible if this doesn’t work to set up subdomains using mod_rewrite?
Thanks for any help, bit of a newbie when it comes to servers 
Looks like your host file (C:\WINDOWS\system32\drivers\etc\) is ok u just need to change the virtual hosts to something like this:
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "c:/dev"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName blog.localhost
DocumentRoot "c:/dev/blog"
</VirtualHost>
Does that work?
I had the same problem on Win2k, and the doodle’s solution still didn’t work, but after a lot of searching I finally found out what was missing: the NameVirtualHost directive. So now I have these lines in httpd.conf:
# Use name-based virtual hosting.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/www/mysite
ServerName mysite.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/www
ServerName localhost
</VirtualHost>
This works very well for me.
Thank you so much Lemon Juice! I’ve been trying to get this working for ages, can’t believe I didn’t try that combination.
Just for anyone else reading this you may need to add your subdomain to your HOSTS file otherwise your browser will probably look for www.subdomain.localhost, which will obviously not work.
FYI -
I tried to use the above instructions, but still managed to get confused. I found this website which made it really easy:
http://apptools.com/phptools/virtualhost.php