莫名其妙的mod_rewrite行为

时间:2014-07-25 12:35:10

标签: apache .htaccess mod-rewrite redirect typo3

我有一个typo3安装,其中包含以下mod_rewrite规则:

只是为了理解mod_rewrite我不想创建以下规则。

如果有人请求没有像“http://domain.com”这样的uri和accept-language en我想要路由到/index.php?id=1&L=1

这是我的.htaccess

   RewriteCond %{REQUEST_URI} !^/ [NC]
   RewriteCond %{HTTP:Accept-Language} ^en [NC]
   RewriteRule ^$ /index.php?id=1&L=1 [R=301,L]

   RewriteRule .* /index.php [L]

我收到500错误。在apache logfile中:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Fri Jul 25 14:14:59 2014] [debug] core.c(3112): [client 188.24.87] r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /index.php
[Fri Jul 25 14:14:59 2014] [debug] core.c(3118): [client 188.24.87] redirected from r->uri = /

我错了什么?

1 个答案:

答案 0 :(得分:0)

您非常接近,但您的上一条规则会多次执行,因为.*在初始重写后匹配index.php。将其更改为:

RewriteRule ^(?!index\.php) /index.php [L]