2014-01-31 101 views
1

我嘗試使用以下命令:阿帕奇重寫尾隨斜線

Redirect 301 /example/cookies http://test.butterscotch.co.uk/cookies?ref=test 

這最終重定向至:

http://test.butterscotch.co.uk/cookies?ref=testexample/cookies 

但是,如果我做的:

Redirect 301 /example/cookies/ http://test.butterscotch.co.uk/cookies?ref=test 

我嘗試網址:

http://oldhost.com/example/cookies/ (with the trailing slash) 

它正確地重定向到新的url。

我需要能夠使用重定向,因此它不必具有結尾斜槓。

回答

1

不確定是什麼原因導致您的第一個問題,但Redirect指令可能不是您在重定向目標中使用查詢字符串時想要的。該`重定向指令類型的連接兩個URL路徑一起,所以如果我有這樣一個規律:

Redirect /abc /xyz 

,我去/abc/,我會很明顯重定向到/xyz/,如果我去/abc/def/g我我會重定向到/xyz/def/g。當我在混合查詢字符串:

Redirect /abc /xyz?i=123 

,我去/abc/def/g,我最終會被重定向到/xyz?i123/def/g,這顯然不是我想要的。

嘗試使用RedirectMatch代替:

RedirectMatch 301 /example/cookies/?$ http://test.butterscotch.co.uk/cookies?ref=test 

或使用mod_rewrite:

RewriteEngine On 
RewriteRule ^example/cookies/?$ http://test.butterscotch.co.uk/cookies?ref=test [L,QSA,R=301]