[英]Apache Virtualhost wrong destination folder
我在Apache 2.4 Websever上为其创建了虚拟主机,但如果尝试加载URL,则路径有时会出错,并且由于未知原因会返回错误。
我有网域“ test.com”
和我的网站可用/默认看起来像这样:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/test/
ServerName test.com/
<Directory /var/www/test/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
如果我现在打电话给URL
"http://www.test.com/" or "www.test.com"
一切都很好,但是如果我尝试加载例如“ test.com”,服务器会将我重定向到
"test.com/test/"
并给我一个404错误。 我不明白为什么它会像这样在某些URL上重定向我。
尝试删除斜杠
ServerName test.com/
DocumentRoot /var/www/test/
并将其更改为
ServerName test.com
DocumentRoot /var/www/test
它的重定向是因为尾部的斜杠指向文档根目录中的test
子目录。
由于这是唯一的vhost配置。 以下是来自Apache文档
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot "/www/domain"
</VirtualHost>
现在您要做的就是添加服务器别名以指定www,以便apache知道如何处理该事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.