Apache 1.3 mod_rewrite .htaccess 循环

Apache 1.3 mod_rewrite .htaccess 循环

当我尝试在 Apache 1.3 的共享主机上部署 CakePHP 应用程序时,mod_rewrite 问题让我束手无策。尽管使用了默认的 .htaccess 文件,我似乎还是被重写循环所困扰,而且反复尝试也无济于事。

在服务器上我的应用程序安装在:

/home/www/myusername/testing

Apache 通过子域符号链接访问该目录:

/home/www/hosts/testing.mydomain.com/

我的 CakePHP 应用程序位于“测试”根目录下,其目录结构如下:

/home/www/myusername/testing/
    webroot/
    controllers/
    etc...        

基本 .htaccess 如下所示(按照默认值):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule    ^$    webroot/    [L]
    RewriteRule   (.*)  webroot/$1    [L]
</IfModule>

webroot .htaccess 如下所示:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

这一切似乎在我的笔记本电脑(使用 Apache 2.2)上都有效,但在服务器上却出现错误,因为它似乎在无休止地重写请求。如果我访问任何 URI(无论是否是基础),我都会在 Apache 错误日志中收到 403 错误:

文件名太长:访问 /home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/ [长时间重复...]

有人能看出什么会导致这里无休止地附加重写吗?我尝试了很多方法,比如添加 RewriteConds 来测试 uri 是否已包含“webroot”,但似乎都不起作用。不过我敢打赌这很明显!

谢谢。

答案1

必须改掉自己回答问题的习惯,但向 SF 发帖似乎打破了僵局。显然需要分别向每个 .htaccess 添加:

RewriteBase /
RewriteBase /webroot

仍然不太确定为什么这些指令是需要的,但我怀疑它与与文档根目录相关的子域“测试”目录有关。

相关内容