[英]Mod_rewrite: Redirect to URL in query string - discard %3f from end of redirected URL
我有一個.htaccess重寫規則,該規則采用以下形式的傳入請求:
IN 1) http://some.domain.com/path/to/index.htm?url=http://take.me/
IN 2) http://some.domain.com/path/to/index.htm?url=http://take.me/another/path/file.htm?key1=val1&key2+val2
我想做的是讓規則提取url
鍵的值並重定向到它的值ergo:
OUT 1) http://take.me/
OUT 2) http://take.me/another/path/file.htm?key1=val1&key2=val2
以下條件和規則適用:
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^index\.htm$ %1? [R,L]`
但是,在OUT 2的情況下,我發現在瀏覽器地址欄中看到的結果URL為:
http://take.me/another/path/file.htm?key1=val1&key2+val2%3f
因此,問題在於將%3f
(百分比編碼的問號)附加到結果URL。 問題是由使用?
在RewriteRule中,但是我需要這樣做,以便丟棄原始查詢字符串。 我不知道%3f
是否會引起問題,因此為了安全起見,我想消除它。 我們正在使用Apache 2.2.22,因此不幸的是沒有查詢字符串丟棄[QSD]
選項。
有沒有辦法在維持規則功能的同時消除%3f
?
您可以將此規則與NE
標志一起使用,這意味着no escaping
結果URL:
RewriteCond %{THE_REQUEST} index\.htm\?url=(\S+) [NC]
RewriteRule index\.htm$ %1? [L,R=302,NC,NE]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.