【发布时间】:2018-10-06 07:40:40
【问题描述】:
我有一个 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
</VirtualHost>
而且效果很好。当我继续sub.mywebsite.com/ 时,它会点击/foo/bar/things 目录,反之亦然。
现在,让我们在/srv/www/new 中添加一个简单的.htaccess:
RewriteEngine on
RewriteRule ^(.*)/$ php/file.php?text=$1 [L,QSA]
所以当我继续 sub.mywebsite.com/pro/hello/ 时,调用的文件应该是带有 GET 参数的 /srv/www/new/php/file.php。我仔细检查了一下,规则很好。
RewriteLogLevel 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]
然后online htaccess checker 确认:The new url is http://sub.mywebsite.com/php/file.php%3Ftext=testing
但我找不到 apache 404:
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
问题:
- 那是什么鬼?为什么error_log中的文件不一样 作为我的浏览器上显示的那个?
- 为什么 apache 无法加载正确的文件
/srv/www/new/php/file.php作为 .htaccess 的要求?
如果需要,请随时向我询问更多数据。我想明白!
注意:/foo/bar/things 中没有 .htaccess ;我在我的虚拟主机中尝试了很多东西,比如添加<directory> 等。
【问题讨论】:
-
您很可能需要将
RewriteBase "/pro"添加到您的 .htaccess 中 -
@DusanBajic 该死的你实际上是对的。你能否在答案中详细说明,也许尝试解释这两个问题,这样我才能接受你的贡献?非常感谢!
-
我可能没有足够的关于 httpd 内部的知识来给出正确的解释,但我会尝试。
标签: apache .htaccess unix alias virtualhost