2011-08-20 60 views
1

我有自己的沙盒/測試系統,我想重寫g/somethingg/something.php爲什麼這個簡單的重寫降到500服務器錯誤?

我用這個很容易重寫規則

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 

回答

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

您更換相匹配,因爲它是如g/test.php這是g/,然後test.ph,然後p,其中不包括.。所以替換被重新替換,等等。結果,重定向溢出(查看Apache錯誤日誌)。

你可能想:

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

因爲匹配g/,那麼沒有點任何東西,然後的URL結束,以確保它的確切URL匹配。

+0

1.我怎樣才能否定不使用[]但具有()正則表達式? 2.這可能是如何工作的? – genesis

+0

否定:http://wiki.apache.org/httpd/RewriteRule。所以'!^ ... $'。該解決方案的工作原理是因爲替換*不*再匹配正則表達式。 – pimvdb

+0

謝謝。當我想重寫g/test/2到g/test-2.php時,我會用什麼? – genesis