mod_rewrite - 防止多个重定向

时间:2011-01-05 17:10:34

标签: apache mod-rewrite

我的文件夹结构:

- nameoftherootfolder
-- app
-- public
--- .htaccess
--- index.php

现在我遇到的问题是,在某些情况下,我的apache经常在内部重写,我收到500服务器错误,这里是日志:

[Wed Jan 05 17:51:54 2011] [error] [client 127.0.0.1] Request exceeded the limit of 3 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Jan 05 17:51:54 2011] [debug] core.c(3046): [client 127.0.0.1] r->uri = /nameoftherootfolder/public/index.php
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/public/index.php
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/public/index.php
[Wed Jan 05 17:51:54 2011] [debug] core.c(3052): [client 127.0.0.1] redirected from r->uri = /nameoftherootfolder/nothere/

我的.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

index.php处理所有请求并处理所访问的URL是否错误,例如不存在。

如果访问的网址存在但它的网址是“错误的”我会收到该错误。 我得到这个就是因为我设置了一个Apache别名:

Alias /nameoftherootfolder/ "C:/somepathshere/WAMP/www/nameoftherootfolder/public/" 

<Directory "C:/somepathshere/WAMP/www/nameoftherootfolder/public/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>

我现在如何使用Apache防止过多的内部重定向?可能有RewriteCond吗? 我正在使用Apache 2.2.11。

修改

如果我在uri中放置一个index.php/它可以工作,但这是SEO不友好,用户不友好并且看起来很可怕,例如请求。 http://localhost/nameoftherootfolder/index.php/nothere/http://localhost/nameoftherootfolder/index.php/index/

编辑#2:

我添加

RewriteBase /nameoftherootfolder/

知道了。

3 个答案:

答案 0 :(得分:6)

我添加

RewriteBase /nameoftherootfolder/

现在有效。

答案 1 :(得分:1)

您需要排除对index.php本身的调用以防止无限循环。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^.*$ index.php [NC,L]

答案 2 :(得分:0)

在我的情况下,我在Apache中配置的另一个站点的文件夹下的子域上有一个站点。这修复了我的重写错误:

RewriteBase /
相关问题