0

这是我的重写代码:

    RewriteEngine On
    RewriteBase "/"
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ http://www.whatever.com/$1/ [R=301,L]

    RewriteRule ^(.*)$ index.php/$1 [L]

这是一个表达式引擎站点。如果我去掉这两条线,该网站就可以正常工作:

    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ http://www.whatever.com/$1/ [R=301,L]

这些是我添加的行,用于在任何 URL 中添加尾部斜杠(如果它没有),以避免在 Google 中重复索引。它导致我的日志文件中出现此错误:请求超出了 l“由于可能的配置错误而导致 10 个内部重定向的限制”

我假设它没有处理 RewriteCond 权利并进入无限循环。关于为什么会发生这种情况的任何想法?

4

3 回答 3

1

这是我的 ExpressionEngine .htaccess ,它删除了斜杠,不确定您是否有偏好,但我认为没有它们看起来会更好。

RewriteEngine on

# get rid of trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php) [NC]
RewriteRule ^(.+)\/$ /$1 [L,R=301]

# no plain index.php either
RewriteRule ^(index\.php)$ / [L,NC,R=301]

# rewrite index.php
RewriteCond $1 !^(images|system|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
于 2011-03-16T03:36:00.677 回答
0

Turn on Rewrite logging (RewriteLogLevel 3 or so should do it), and most like you'll see the request getting bounced back and forth between

 www.whatever.com/blah
 www.whatever.com/blah/
 www.whatever.com/blah
 www.whatever.com/blah/
 www.whatever.com/blah
 www.whatever.com/blah/
 etc....
于 2011-03-02T16:38:07.057 回答
0

一、原则:任何重写后,从头开始处理整个规则集。该[L]标志不会阻止这一点;它控制规则是否是当前运行中的最后一个。

在这种情况下,问题是最后一条规则。它重写了这样的任何东西:

foo → index.php/foo → index.php/index.php/foo → ...

当您删除这两行时,此规则会附加!-fand!-d条件,从而防止循环。

从行的分组看来,您希望将这两个条件附加到所有以下规则。您不能这样做,但是您可以将相反的条件附加到将停止处理的规则:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
于 2011-03-02T18:37:17.257 回答