2015-09-03 69 views
2

我試圖重定向從;htaccess從多個網址重定向到單個並刪除查詢字符串

http://www.example.com/news/newsitem.asp?story=20130227 
http://www.example.com/news/newsitem.asp?story=20148893 

還有其他的網址,我不知道,所以希望一切從新聞重定向/ newsitem.asp 到

http://www.example.com/blog 

我使用

RewriteRule ^news/newsitem.asp http://www.example.com/blog [R=301,L] 

但結果將查詢字符串添加到末尾

結果= http://www.example.com/blog?story=20130227

如何阻止查詢字符串被追加?

我發現這個職位,但似乎無法使它工作 redirect a single URL to another - removing the query string

回答

1

您可以使用:

RewriteRule ^news/newsitem\.asp$ /blog/? [R=301,L,NC] 

?到底會去掉所有預先存在的查詢字符串。

更好的逃避DOT在正則表達式中,並確保在清除瀏覽器緩存後進行測試。

0

您需要添加一個「?」重寫目標末尾

RewriteRule ^news/newsitem.asp$ http://www.example.com/blog? [R=301,L] 

最後爲空的問號很重要,因爲它會丟棄來自url的原始查詢字符串。

相關問題