Need help with xampp virtual host

I am using XAMPP, Apache 2.2.17. I added a virtual host, but my virtual host and localhost both point to the same place. 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 code above, I get tests with www.domain.tld, so that’s good. But if I type localhost, it will go to testite as well. If I move ahead of the test site, then localhost goes to localhost, and www.domain.tld also goes to localhost. I tried different settings for localhost as

<VirtualHost *>
<VirtualHost localhost:80>

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

+5
source share
3 answers

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>
+3
source
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>
+3

, ServerName IP-, 127.0.0.2.

_ domain.tld - "domain.com", .tld .com .

-1
source

All Articles