Page 1 of 1

Always redirects to first virtual host defined [SOLVED]

PostPosted: 02. January 2012 19:05
by Jstall
Hello all,

I am running the latest version of XAMPP on Windows 7. I am attempting to enable virtual hosts. The issue is that the first virtual host defined in my httpd-vhosts.conf file is always the one that the browser gets redirected to. Here is my httpd-vhosts.conf file:

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName bru.jay
DocumentRoot "C:\xampp\htdocs\bru\html"
</VirtualHost>

<VirtualHost *:80>
ServerName test.jay
DocumentRoot "C:\xampp\htdocs\test\html"
</VirtualHost>


If I go to either bru.jay or test.jay I am redirected to C:\xampp\htdocs\bru\html, however if I change the order in which they are defined I will go to C:\xampp\htdocs\test\html . I have the line
Code: Select all
Include "conf/extra/httpd-vhosts.conf"


un-commented in my httpd.conf file. I'm not sure what I am missing here. Could anyone suggest what is wrong? Any help is appreciated. Thanks much.

Re: Always redirects to first virtual host defined

PostPosted: 02. January 2012 19:10
by Altrea
Hi Jstall,

Jstall wrote:the first virtual host defined in my httpd-vhosts.conf file is always the one that the browser gets redirected to.

Thats because the first VHost is always the default VHost. Every request on which no other VHost matches, the default VHost will be used.

Jstall wrote:I'm not sure what I am missing here. Could anyone suggest what is wrong?

Have you added these URLs to your \Windows\system32\drivers\etc\HOSTS file?

best wishes,
Altrea

Re: Always redirects to first virtual host defined

PostPosted: 02. January 2012 19:20
by Sharley
Try this:
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost *:80>
ServerName bru.jay
DocumentRoot "C:/xampp/htdocs/bru/html"
</VirtualHost>

<VirtualHost *:80>
ServerName test.jay
DocumentRoot "C:/xampp/htdocs/test/html"
</VirtualHost>
Save the file and restart Apache.

Your C:\Windows\system32\drivers\etc\HOSTS file should have the first entries after all the comments looking like this
Code: Select all
127.0.0.1 localhost
127.0.0.1 bru.jay
127.0.0.1 test.jay
Clear your browser's cache from time to time when working at localhost level.

Let me know how the above pans out.

Good luck. :)

Re: Always redirects to first virtual host defined

PostPosted: 02. January 2012 20:25
by Jstall
Hello,

That did it! The hosts file edit was the missing piece. Thanks much for the help I really appreciate it.

Re: Always redirects to first virtual host defined

PostPosted: 02. January 2012 20:26
by Sharley
Would you be so kind as to add your XAMPP version and Operating System to your profile as per these instructions:
viewtopic.php?f=16&t=48626
Thanks. :)


Thanks also for the feedback. 8)

I will close this topic and mark it solved.

Any other issues please feel free to start a new topic.

Best wishes. :)