need help with xampp virtual host

15,107

Solution 1

My own answer: The following code fixed the problem

<VirtualHost *:80> <--- * fixed the problem, apache 2.2 doc does say it must match www.domain.tld, which caused problem for other Virtual hosts
ServerName www.domain.tld
ServerAlias domain.tld 
DocumentRoot "C:/xampp/htdocs/workspace/patriot2"
</VirtualHost>

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

Solution 2

NameVirtualHost *:80

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

<VirtualHost *:80>
    ServerName mydomain.local
    ServerAlias www.mydomain.local 
    DocumentRoot C:/mysite/htdocs
</VirtualHost>
Share:
15,107
Hammad Khan
Author by

Hammad Khan

Humble, down to earth, experience software Engineer 12+ years of industry experience in ASP.NET, SQL Server, C/C++, Web Development, Automation

Updated on June 17, 2022

Comments

  • Hammad Khan
    Hammad Khan over 1 year

    I am using XAMPP, Apache 2.2.17. I have added virtual host but my virtual host and localhost both point to the same location. Here is my code in httpd-vhosts.conf

    <VirtualHost www.domain.tld:80>
    ServerName www.domain.tld
    ServerAlias domain.tld *.domain.tld
    DocumentRoot "C:/xampp/htdocs/workspace/testsite"
    </VirtualHost>
    
    <VirtualHost *:80>
       DocumentRoot "C:/xampp/htdocs/xampp"
       ServerAlias localhost
       ServerName localhost
    </VirtualHost>
    

    With the above code, I get testsite with www.domain.tld so that is good. But If i type localhost, it will go to testsite as well. If I move ahead of test site then localhost goes to localhost good and www.domain.tld goes to localhost too. I tried different setting for localhost as like

    <VirtualHost *>
    <VirtualHost localhost:80>
    

    and removing *.domain.tld from domain.tld but nothing works. Am I missing something obvious?

  • Hammad Khan
    Hammad Khan about 12 years
    I tried 127.0.0.1 before but did not work. Tried it again, did not work + tried <VirtualHost 127.0.0.2:80>, did not work.
  • May Phyu
    May Phyu over 6 years
    could you please take a look at my problem bro stackoverflow.com/questions/45173872/… ?