Forum Moderators: phranque
As I see it, I have two things to do. First, add a line to my Windows HOSTS file so that all requests for www.site1.com go to 127.0.0.1. Second, add the virtual host for www.site1.com to my httpd.conf file so that Apache directs requests for that domain to the proper directory on my local drive.
My problem is I don't know how to set up the virtual host section. I've read through several online tutorials, but none of them seem to make anything very clear.
I want all requests for www.site1.com to be routed to C:\xampp\htdocs\site1
My specific questions are going to seem like "please do my homework for me" type of questions, but I'm really lost. So if someone could just give me the answers, then possibly explain a bit of the reasoning behind the answers, I'm sure I'll be able to do this alone next time! ;)
So anyway, here are the questions I have right now:
What I've Done So Far:
So far, I've added the following line to my Windows hosts file:
127.0.0.1 www.site1.com
So far so good; whenever I have Apache running and try to go to www.site1.com it goes right to the index page in my /htdocs directory.
I've also tried adding the Virtual Host to my httpd.conf file:
<VirtualHost *>
ServerName www.site1.com
DocumentRoot /htdocs/site1
DirectoryIndex index.html
</VirtualHost>
For the DocumentRoot line, I've tried using forward / and backward \, and have tried both kinds of slashes with full and relative paths. None of it has any effect; going to www.site1.com still loads up the index page for /htdocs instead of the index page for /htdocs/site1.
Any and all help to get this straightened out will be greatly appreciated.
Matthew
<VirtualHost *>
ServerName www.site1.com
DocumentRoot /htdocs/site1
DirectoryIndex index.html
</VirtualHost>
The basic syntax looks good, but your path is wrong. Most of the examples in the Apache documentation are for use on Linux/other Unix servers where the paths use slashes and no drive name. In your case, you need to specify the full Windows path to the document root. You should also start your list of virtual hosts with a
NameVirtualHost * as well if you haven't already got it: NameVirtualHost *
<VirtualHost *>
ServerName www.site1.com
[b]DocumentRoot C:\xampp\htdocs\site1[/b]
DirectoryIndex index.html
</VirtualHost> Once this is in your httpd.conf, restart Apache. If it fails to restart, check the error log for details. Other than that, your approach looks good!