[英]Redirect a URL with querystring to to a new URL with same querystring
[英]How to redirect a URL with a querystring
我已將網站移至新域,並使用RewriteRule
重定向了許多URL。
我在嘗試使用其中的查詢字符串重定向URL嗎?
RewriteRule /news/archive.php?cat=economic-impact http://www.new-website.com/faqs/economic-impact [R=301,L]
RewriteRule /news/archive.php?cat=housing-need http://www.new-website.com/faqs/housing-need R=301,L]
RewriteRule /news/archive.php?cat=infrastructure http://www.new-website.com/faqs/infrastructure R=301,L]
進一步訪問htaccess
文件,我正在使用它來重定向域
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-website.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-website.com$
RewriteRule (.*)$ http://www.new-website.com/$1 [R=301]
當我訪問時:
old-website.com/news/archive.php?cat=economic-impact
它重定向到
new-website.com/news/archive.php?cat=economic-impact
我需要重定向到哪個404s:
new-website.com/faqs/economic-impact
有人可以幫忙嗎?
您需要在重寫中添加一個空白查詢字符串以截斷所有現有查詢字符串。
下面應該做的工作:
RewriteRule (.*)$ http://www.new-website.com/$1? [R=301]
此外,檢查現有查詢字符串的方式將不起作用。 您需要單獨檢查它們:
RewriteCond %{QUERY_STRING} "cat=(economic-impact|housing-need|infrasructure)"
RewriteRule news/archive.php http://www.new-website.com/faqs/%1? R=301,L]
%1
將從RewriteCond
的正則表達式組匹配中進行反向引用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.