我要自己回答這個問題,因爲我碰到它並找不到一個Google結果來幫助,所以希望這可以節省一些未來的人一些時間。帶文本選項的RewriteMap總是返回沒有結果
在APACHE2.2,我有塑造這樣一個RewriteMap指令,重定向到URL如果一個特定的查詢字符串參數存在:
RewriteMap redirect "txt:/etc/arbitrary1/arbitrary2/redirect.txt"
RewriteCond %{QUERY_STRING} (^|&)foo=([^&]+) [NC]
RewriteCond ${redirect:%1} !^$
RewriteRule ^.*$ ${redirect:%1} [301,L]
而且/etc/arbitrary1/arbitrary2/redirect.txt
:
foo http://hello.invalid/somepath/1 # 1
bar http://hello.invalid/somepath/2 # 2
baz http://hello.invalid/somepath/3 # 3
問題我遇到過,無論我使用哪一個「foo,bar,baz」,${redirect:%1}
指令都會返回空白(即「不匹配」)。這與redirect.txt
的格式無關。請參閱以下我發現的內容。