需要xampp虚拟主机的帮助

Ham*_*han 5 xampp virtualhost

我正在使用XAMPP,Apache 2.2.17.我添加了虚拟主机,但我的虚拟主机和localhost都指向同一位置.这是我在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>
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我得到了带有www.domain.tld的testsite,这很好.但是,如果我键入localhost,它也将转到testsite.如果我在测试站点之前移动,那么localhost会转到localhost,而www.domain.tld也会转到localhost.我尝试了localhost的不同设置

<VirtualHost *>
<VirtualHost localhost:80>
Run Code Online (Sandbox Code Playgroud)

并从domain.tld中删除*.domain.tld但没有任何作用.我错过了一些明显的东西吗

Ham*_*han 3

我自己的答案:以下代码解决了问题

<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>
Run Code Online (Sandbox Code Playgroud)