I am running xampp which has Apache on windows for a dev server. I need to use a subdomain of localhost to access my localhost/images/ folder by going to h##p://images.localhost
However I am having trouble, I have posted an image below showing my problem.
So the question is how to you setup a subdomain on Apache and actually have it work for a folder like I need?
Please view this image, sorry new users can't post more then 1 url and NO images so here is my 1 url to an important image
http://www.freeimagehosting.net/uploads/b0194b8e68.jpg
UPDATED VERSION
My apache conf file
NameVirtualHost localhost:8080
<VirtualHost localhost:8080>
ServerName localhost
ServerAdmin [email protected]
DocumentRoot c:\server\htdocs
</VirtualHost>
<VirtualHost images.localhost:8080>
ServerName images.localhost
ServerAdmin [email protected]
DocumentRoot c:\server\htdocs\images
</VirtualHost>
My windows host file
127.0.0.1 images.localhost
127.0.0.1 *.localhost
The problem, as far as I understand Apache virtual hosting anyway, is that you're using a catch-all in your Virtual hosts config and using a mutual DocumentRoot, rather than explicitly defining each VHost's name and DocumentRoot:
*:8080 is your base NameVirtualHost setting.
This will catch all requests to :8080, and it will redirect all requests to the virtual host that matches the directive.
It becomes problematic when you have two Vhost directives that are named the same thing, and one of the directive's DocumentRoot matches the server's DocumentRoot. If there is no "Overriding" DocumentRoot that the server has separately, then Apache will evaluate each Vhost's DocumentRoot, finding the "Occam's Razor" of the values it encounters if multiple Vhost's share a root path.
In this case ...\htdocs is the DocumentRoot for both, because ...\images is contained within ...\htdocs. Thus any requests will automatically default to the Vhost that offers only ...\htdocs as its DocumentRoot.
I realize that was a bit confusing, so to fix this: Switch to name based virtual hosting.
UPDATE (2009-08-25)
There's something I need to clarify before we move on:
Apache and other web servers never listen on :8080 by default. Also, web clients like Firefox never make a request to :8080 by default. I assumed that you understood that from your original post, since your VHost directive showed a non-standard port of :8080. Now, I'm not so sure that was clear.
In order for the previous revision of my post to have worked for you as it was setup (without port 80 redirects or what have you), you would need to specify the port when requesting a page:
http://localhost:8080 and http://images.localhost:8080
I should have included that information. As I said, I assumed that was clear from your original post. My apologies for that. By extension, I also assumed you were setting it up this way because another server was listening on port 80. If that's true, then you might consider combining the two servers into one setup, or turn off the alternate while you do your work with xampp.
So, let's correct the VHost directives to listen to port 80, which is the default port that pages are served from, and requested from, by servers and clients respectively.
I'm also going to get anal retentive about defining the localized permissions for the folders that you're serving data from, since I'm worried that there is a / Directive that is munging your ability to get pages from your sites.
UPDATED VirtualHost Directives (2009-08-25):
Apache will get grumpy about this setup if there is no corresponding DNS name that it can find for a virtual host, so the recommendation earlier about modifying the systems's hosts file is still accurate. Note that when you edit the hosts file, you can put all the aliases for a single IP on the same line, saving you some confusion.
You can also do IP based Vhosting but I wouldn't recommend it. It's much more involved than what you're doing and is only "really" necessary when you're dealing with multiple vHosts using SSL.
Anyway, the setup I've described works exactly as expected on my system (Ubuntu 8.10 x86_64, Apache 2.2.9) and should also work fine on yours.
I would imagine that your problem is trying to do a subdomain of "localhost". Best thing to do would be to change your servernames to something like "localdomain.com" and "images.localdomain.com" (anything will do really), and then modify your hosts file to map that domain to 127.0.0.1
Been a while since I've used windows (sorry), but I believe the hosts file is in c:\windows\system32\etc\hosts
And the format for the fake domain would be something like:
Then, you'd just need to bounce your XAMPP server and everything should be good to go.
Hope that helps :)
Configuration looks fine to me. Check for simple issues like restarting apache after changing configuration file, etc.
As described in the RFC 2606 .localhost. is treated special.
But one other thing to look at: What is your default directory? It could be that non of your virtual settings are working properly. But instead the DocumentRoot of the server itself is always handling the requests.
The problem is that 'localhost' always resolves to 127.0.0.1 but subdomains of localhost such as your 'images.localhost' are not defined and therefore are not resolving. You can correct this locally by editing your system's hosts file (usually in c:\windows\system32\drivers\etc) and adding the following line:
You could also add:
After saving the hosts file, your subdomains should resolve correctly.
Edit: I see that you have the vhosts configured to listen on port 8080 but your URLs don't include the port number. You need to browse to the addresses with :8080 in them like this:
Alternatively, you can change the vhosts to listen on :80.
I'm guessing the reason just localhost works is that your primary Apache conf has a
Listen 127.0.0.1
andDocumentRoot c:\xampp\htdocs
.Maybe you have a problem with name resolution. You can try "ping images.localhost" from command line (Start -> Run -> "cmd")
If that subdomain isn't working, maybe you can try with a real one. My last article might help: 42foo: all the virtual hosts you need for your web development
I have this working on some domains, although I link them all to the same document root: