2012-03-20 88 views
0

我環顧四周尋找答案,沒有運氣。需要.htaccess重寫規則建議

我想要做的就是更換

http://localhost/mysite/superv/something

http://localhost/mysite/superv/?p=something

這是我從昨天起想出了最佳配方:

RewriteEngine On 
RewriteBase /mysite/ 
RewriteRule ^(superv/)([^\?/]+)$ $1\?p=$2 [NC] 

但它不工作。

我覺得「RewriteBase」啄無關的問題,因爲這條線的工作就像一個魅力:

RewriteRule ^(javascripts/main\.js)$ $1\.php [NC]

編輯:右鍵Rekire,這是一個錯誤,而複製和粘貼代碼。我現在解決了這個問題。

EDIT2:下面是出現在Apache日誌錯誤:

[Tue Mar 20 20:26:01 2012] [error] [client 127.0.0.1] 
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. 

我猜問題是 「循環」,我引述:

Looping occurs when the target of a rewrite rule matches the pattern. 
This results in an infinite loop of rewrites 
+0

那麼,如果你寫入你的'RewriteRule'「superv」,但你試圖用「admin」來管理一個URL,那麼這是行不通的。 – rekire 2012-03-20 17:31:47

+0

請注意,評論者不會被通知編輯。我想知道你正試圖將用戶重定向到一個php文件的路徑。這可能是你的問題。 – rekire 2012-03-20 18:14:01

+0

請勿在替換字符串中轉義字符,例如'$ 1嗎?P = $ 2'。另外你爲什麼[內部]重定向'http:// localhost/mysite/javascripts/main.js'到'http:// localhost/mysite/javascripts/main.js.php'? – TerryE 2012-03-20 20:36:57

回答

1

出於某種原因,這個公式的工作(內部重定向):

RewriteRule (.*)(superv/)?(.*) $1$2index.php?p=$3 [NC,QSA] 

這似乎已經打破了「無限循環」。

1

這似乎是爲我工作。

RewriteRule ^(superv/)([^\?/]+)$ $1?p=$2 [R,NC] 

刪除R,如果你想做一個內部重定向。

+0

嗨,您的線路工作,但一旦我刪除R我得到相同的「500內部服務器錯誤」和「請求超出限制」錯誤。 – 2012-03-21 15:47:30