简体   繁体   English

Apache Virtualhost错误的目标文件夹

[英]Apache Virtualhost wrong destination folder

I created a virtual host for on my Apache 2.4 Websever but if I am trying to load the URL the path is sometimes wrong and I get an error back by unknown reason. 我在Apache 2.4 Websever上为其创建了虚拟主机,但如果尝试加载URL,则路径有时会出错,并且由于未知原因会返回错误。

I have the domain "test.com" 我有网域“ test.com”

and my sites-available/default looks like this: 和我的网站可用/默认看起来像这样:

NameVirtualHost *:80

<VirtualHost *:80>
     DocumentRoot /var/www/test/
     ServerName test.com/

     <Directory /var/www/test/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
     </Directory>
</VirtualHost>

If I am calling now the URL 如果我现在打电话给URL

"http://www.test.com/" or "www.test.com" 

everything is fine but if I try to load for example "test.com" the server redirects me to 一切都很好,但是如果我尝试加载例如“ test.com”,服务器会将我重定向到

"test.com/test/" 

and gives me a 404 Error. 并给我一个404错误。 I don't understand why it is redirecting me like that on some URLs. 我不明白为什么它会像这样在某些URL上重定向我。

Try removing the trailing slash 尝试删除斜杠

ServerName test.com/
DocumentRoot /var/www/test/

And change it to 并将其更改为

ServerName test.com
DocumentRoot /var/www/test

Its redirecting you becuase the trailing slash is pointing to the test sub directory in the document root. 它的重定向是因为尾部的斜杠指向文档根目录中的test子目录。

Since this is the only vhost config. 由于这是唯一的vhost配置。 The following is from the apache documentation 以下是来自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>

Now all you have to do is add a server alias to specify www so that apache knows how to handle the event 现在您要做的就是添加服务器别名以指定www,以便apache知道如何处理该事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM