apachevhost:别名和重写规则
我有一个URL(域),用于多个目录(项目)。当我在里面放一个.htaccess时,我有一个非常奇怪的行为apachevhost:别名和重写规则,apache,.htaccess,unix,alias,virtualhost,Apache,.htaccess,Unix,Alias,Virtualhost,我有一个URL(域),用于多个目录(项目)。当我在里面放一个.htaccess时,我有一个非常奇怪的行为 sub.mywebsite.com/=>/foo/bar/things sub/mywesite.com/pro=>/srv/www/new 虚拟主机: <VirtualHost *:80> DocumentRoot /foo/bar/things ServerName sub.mywebsite.com Alias /pro /srv/www/new
=>sub.mywebsite.com/
/foo/bar/things
=>sub/mywesite.com/pro
/srv/www/new
<VirtualHost *:80>
DocumentRoot /foo/bar/things
ServerName sub.mywebsite.com
Alias /pro /srv/www/new
</VirtualHost>
因此,当我转到sub.mywebsite.com/pro/hello/
时,调用的文件应该是带有GET参数的/srv/www/new/php/file.php
。我仔细检查了一下,规则是好的
下面是第4级的结尾:
192.168.123.123 - - [25/Apr/2018:19:28:11 +0200] [sub.mywebsite.com/sid#7f317dd08b8][rid#7f37eca9f78/initial] (1)
[perdir /srv/www/new/] internal redirect with /srv/www/new/php/file.php [INTERNAL REDIRECT]
并确认:新的url是http://sub.mywebsite.com/php/file.php%3Ftext=testing
但我找不到Apache404:
Not Found
The requested URL /srv/www/new/php/file.php was not found on this server.
是的,ls-l/srv/www/new/php/file.php
文件存在
非常奇怪的是:在apache错误日志中,我得到:
[Wed Apr 25 19:45:30 2018] [error] [client 192.168.123.123] File does not exist: /foo/bar/things/srv
问题:
/srv/www/new/php/file.php
注意:
/foo/bar/things
中没有.htaccess;我在vhost中尝试了很多东西,比如添加
,等等。您的屏幕和日志中已经显示了您两个问题的答案:
The requested URL /srv/www/new/php/file.php was not found on this server.
请求的URL
AH00128: File does not exist: /foo/bar/things/srv/www/new/php/file.php
文件不存在
因此,apache没有试图获取文件系统上/srv/www/new/php/
文件夹中的文件file.php
。它正在尝试打开URLhttp://sub.mywebsite.com/srv/www/new/php/file.php
,它解释了浏览器错误和错误日志中的行,因为对于该URL,它确实应该查看/foo/bar/things/srv/www/new/php/file.php
发件人:
重写引擎可在.htaccess文件和中使用
部分,但有一些额外的复杂性。(…)
请参阅 指令获取有关前缀的更多信息 将被添加回相对替换。
(…)
RewriteBase指令指定要用于的URL前缀 每目录(htaccess)重写替换 相对路径。当您使用亲属关系时,此指令是必需的 每个目录(htaccess)上下文中替换中的路径。
(…)
这种错误配置通常会导致服务器查找 文档根目录下的目录 解决方案:在.htaccess中添加
RewriteBase”/pro“
您可以在重写日志中看到差异:
无基础:
[perdir /srv/www/new/] rewrite 'hello/' -> 'php/file.php?text=hello'
[perdir /srv/www/new/] add per-dir prefix: php/file.php -> /srv/www/new/php/file.php
[perdir /srv/www/new/] internal redirect with /srv/www/new/php/file.php [INTERNAL REDIRECT]
使用RewriteBase”/pro“
:
这两个问题的答案已显示在屏幕和日志中:
The requested URL /srv/www/new/php/file.php was not found on this server.
请求的URL
AH00128: File does not exist: /foo/bar/things/srv/www/new/php/file.php
文件不存在
因此,apache没有试图获取文件系统上/srv/www/new/php/
文件夹中的文件file.php
。它正在尝试打开URLhttp://sub.mywebsite.com/srv/www/new/php/file.php
,它解释了浏览器错误和错误日志中的行,因为对于该URL,它确实应该查看/foo/bar/things/srv/www/new/php/file.php
发件人:
重写引擎可在.htaccess文件和中使用
部分,但有一些额外的复杂性。(…)
请参阅 指令获取有关前缀的更多信息 将被添加回相对替换。
(…)
RewriteBase指令指定要用于的URL前缀 每目录(htaccess)重写替换 相对路径。当您使用亲属关系时,此指令是必需的 每个目录(htaccess)上下文中替换中的路径。
(…)
这种错误配置通常会导致服务器查找 文档根目录下的目录 解决方案:在.htaccess中添加
RewriteBase”/pro“
您可以在重写日志中看到差异:
无基础:
[perdir /srv/www/new/] rewrite 'hello/' -> 'php/file.php?text=hello'
[perdir /srv/www/new/] add per-dir prefix: php/file.php -> /srv/www/new/php/file.php
[perdir /srv/www/new/] internal redirect with /srv/www/new/php/file.php [INTERNAL REDIRECT]
使用RewriteBase”/pro“
:
您很可能需要将
RewriteBase”/pro“
添加到您的应用程序中。htaccess@DusanBajic该死的,你说得对。。请你在回答中详细说明一下,或者试着解释这两个问题,这样我就可以接受你的贡献了?非常感谢!我可能没有足够的关于httpd内部的知识来给出正确的解释,但我会尝试。您很可能需要将RewriteBase”/pro“
添加到您的应用程序中。htaccess@DusanBajic该死的,你说得对。。请你在回答中详细说明一下,或者试着解释这两个问题,这样我就可以接受你的贡献了?非常感谢!我可能没有足够的关于httpd内部的知识来给出适当的解释,但我会尝试。