我有以下重寫設置:htaccess的通用重寫規則
RewriteRule r/(.*) scripts/report.php?cp=1&id=$1
它的偉大工程重定向mydomain.com/r/123abc但它重定向是有「R」開頭的服務器上的所有網頁。有誰知道我可以使這個更具體的只有當網址是mydomain.com/r/時重定向? 我應該注意,我需要保持這個通用性,所以我不能在規則中包含mydomain.com。
我有以下重寫設置:htaccess的通用重寫規則
RewriteRule r/(.*) scripts/report.php?cp=1&id=$1
它的偉大工程重定向mydomain.com/r/123abc但它重定向是有「R」開頭的服務器上的所有網頁。有誰知道我可以使這個更具體的只有當網址是mydomain.com/r/時重定向? 我應該注意,我需要保持這個通用性,所以我不能在規則中包含mydomain.com。
嘗試在您的r/(.*)
重寫規則之前放置一個^/
。這將使:
RewriteRule ^/r/(.*) scripts/report.php?cp=1&id=$1
我不知道這是否適用於你(未測試),但嘗試一下:
# Rewrite ini
RewriteEngine on
RewriteBase /mydomain.com/
# Redirect all /mydomain.com/r/* calls to scripts/report.php
RewriteRule ^r/(.*)$ scripts/report.php?cp=1&id=$1 [QSA]
希望有所幫助。
您應該指定一個正則表達式應該匹配整個字符串而不是僅僅匹配字符串。感謝 -
RewriteRule ^r/(.*)$ scripts/report.php?cp=1&id=$1
啊完美:您可以使用
^
和$
符號做到這一點 – cronoklee 2012-04-05 15:55:02