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.
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
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:
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.
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.
I tried to use the above instructions, but still managed to get confused. I found this website which made it really easy: