Always redirects to first virtual host defined [SOLVED]

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Always redirects to first virtual host defined [SOLVED]

Postby Jstall » 02. January 2012 19:05

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.
Jstall
 
Posts: 13
Joined: 07. July 2010 20:20

Re: Always redirects to first virtual host defined

Postby Altrea » 02. January 2012 19:10

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Always redirects to first virtual host defined

Postby Sharley » 02. January 2012 19:20

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. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Always redirects to first virtual host defined

Postby Jstall » 02. January 2012 20:25

Hello,

That did it! The hosts file edit was the missing piece. Thanks much for the help I really appreciate it.
Jstall
 
Posts: 13
Joined: 07. July 2010 20:20

Re: Always redirects to first virtual host defined

Postby Sharley » 02. January 2012 20:26

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. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 186 guests