2010-10-14 120 views
0

我有這個網址,我想使友好,使用上.htacess重寫,但它給我一個錯誤(500內部服務器錯誤),這是我的原單的PHP網址htaccess重寫給我500錯誤?

http://www.example.com/viewtopic.php?topic=lovetopic 

我想將其更改爲這樣的:

http://www.example.com/lovetopic 

,這是我的整個htaccess的代碼是這樣的:

RewriteEngine On 
RewriteRule ^user/([^/]*)$ /viewprofile.php?user=$1 [L] 
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L] 

我不知道是什麼問題

編輯服務器錯誤日誌是給我這個錯誤

[Thu Oct 14 20:34:36 2010] [error] 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., 
+0

您是否檢查編輯日誌? – 2010-10-14 19:34:09

+0

我把什麼服務器錯誤日誌給我了,謝謝:)) – getaway 2010-10-14 19:37:53

+0

因爲我把主題URL的重寫,它一直給我這500個內部錯誤 – getaway 2010-10-14 19:38:44

回答

4

你的第二個規則^([^/]*)$的模式不匹配也沒有/viewtopic.php路徑前綴/,即viewtopic.php。這就是爲什麼你有無限遞歸。

您可以使用以下條件排除:

RewriteCond $1 !=viewtopic.php 
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L] 

或者用這個條件來排除所有現有文件:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L] 

或者使用此規則在你的其他規則前停止每個可以映射到現有文件的請求都將被以下規則重寫:

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 
+0

不應該''[L]'標記已經防止遞歸? – Powerlord 2010-10-14 19:51:18

+0

D'oh,我剛剛檢查了......不,'[L]'不會阻止內部重定向導致所有規則在新的url上被重新處理。 – Powerlord 2010-10-14 19:51:59

+0

@R。 Bemrose:不,[* L * flag](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags)有點不同:「但請記住,如果RewriteRule生成一個內部重定向(當在每個目錄上下文中重寫時經常發生),這將重新注入請求,並且會導致從第一個RewriteRule開始重複處理。「 – Gumbo 2010-10-14 19:52:38