Redirect 创建localhost子域会重定向所有localhost链接

Redirect 创建localhost子域会重定向所有localhost链接,redirect,subdomain,localhost,wamp,Redirect,Subdomain,Localhost,Wamp,我正在尝试使用Wamp在本地主机上设置子域。我正在创建的子域是store.localhost,现在我可以让该子域正常工作,但是当我在url中使用localhost转到其他任何内容时,它会重定向到store.localhost。所以只需重定向到store.localhost 我的主机文件包含以下内容: 127.0.0.1 localhost 127.0.0.1 store.localhost 我的httpd-vhosts.conf文件包含: <VirtualHost *:80>

我正在尝试使用Wamp在本地主机上设置子域。我正在创建的子域是store.localhost,现在我可以让该子域正常工作,但是当我在url中使用localhost转到其他任何内容时,它会重定向到store.localhost。所以只需重定向到store.localhost

我的主机文件包含以下内容:

127.0.0.1 localhost

127.0.0.1 store.localhost
我的httpd-vhosts.conf文件包含:

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/store"
    ServerName store.localhost
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>

DocumentRoot“C:/wamp/www/store”
ServerName store.localhost
ErrorLog“logs/error.log”
CustomLog“logs/access.log”通用
我已经取消了httpd.conf中关于虚拟主机的注释


那么我做错了什么呢?

您是否使用ServerName localhost定义了另一个VirtualHost?如果没有,那么Apache将使用第一个定义的VirtualHost来处理请求,因此您可能需要这样的东西

#catch all server
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/catchall"
    ServerName localhost
</VirtualHost>

#store.localhost
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/store"
    ServerName store.localhost
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>
#捕获所有服务器
DocumentRoot“C:/wamp/www/catchall”
服务器名本地主机
#store.localhost
DocumentRoot“C:/wamp/www/store”
ServerName store.localhost
ErrorLog“logs/error.log”
CustomLog“logs/access.log”通用

有关更多信息,请参阅上的Apache手册部分。

唯一定义的虚拟主机是存储区的虚拟主机。那么我应该使用你在vhosts文件中发布的内容吗?我只是试了一下,当store.localhost工作时,我得到了404的其他任何东西。没关系,我似乎已经让它工作了。我刚刚让servername localhost块指向www目录。谢谢你的帮助:)