为什么这个简单的重写会降到500服务器错误?

时间:2011-08-20 13:30:59

标签: .htaccess

我有自己的沙盒/测试系统,我想将g/something重写为g/something.php

我使用了这个非常简单的重写规则

RewriteEngine on
RewriteRule ^g/(.*?)[^\.]+ g/$1.php [L]

问题:

  • 我如何否定我的统治? (这意味着只有当请求的文件没有以.php结尾时才会触发此规则。我已尝试(^\.php)(!\.php)但没有任何效果,因此我使用了[^\.]
  • 为什么这一行会引发500内部服务器错误?

错误日志:

[Sat Aug 20 15:47:53 2011] [error] [client myip] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRec
[Sat Aug 20 15:47:53 2011] [debug] core.c(3063): [client myip] r->uri = /g/..........php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/.........php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/........php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/.......php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/......php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/.....php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/....php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/...php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/..php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/.php
[Sat Aug 20 15:47:53 2011] [debug] core.c(3069): [client myip] redirected from r->uri = /g/64002

1 个答案:

答案 0 :(得分:2)

^g/(.*?)[^\.]+

匹配您的替代品,因为它是例如g/test.php g/,然后是test.ph,然后是p,其中不包含.。因此,替换会再次被替换,等等。因此,重定向溢出(请查看Apache错误日志)。

你可能想要:

^g/([^.]*?)$

因为它匹配g/,然后匹配任何没有点的内容,然后结束网址以确保它与确切的网址匹配。