簡體   English   中英

通過重定向htaccess附加查詢字符串

[英]Appending query string through redirect htaccess

我試圖在htaccess中創建一個重寫條件,我試圖重定向

http://www.example.com/business/search-results.php?keywords=Animal+Business+Cards&go=Search

http://www.example.com/business/search results.php?keywords=Animal+Business&go=Search

或者,如有可能,從任何搜索查詢中刪除“ + cards”一詞...

到目前為止我嘗試過的

RewriteEngine On
RewriteCond   %{QUERY_STRING}   ^Animal+Business+Cards$
RewriteRule   ^(.*)$ http://www.example.com/business/search-results.php?keywords=Animal+Business  [R=301,L]

也嘗試過

RewriteCond %{QUERY_STRING}    "&go=Search" [NC]
RewriteRule (.*)  /$1? [R=301,L]

和這個

Redirect /business/search-results.php?keywords=Animal+Business+cards&go=Search http://www.example.com/business/search-results.php?keywords=Animal+Business&go=Search

這些都不起作用...有可能嗎? 有人可以幫忙嗎? 先感謝您

試試下面的代碼:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^keywords=([^\+]+)\+([^\+]+)\+([^&]+)&go=([^&]+)$ [NC]
RewriteRule ^ %{REQUEST_URI}?keywords=%1+%2&go=%4 [NC,L,R]

另一種解決方案

RewriteEngine On

RewriteCond %{THE_REQUEST} \?keywords=([^\+]+)\+([^\+]+)\+([^&]+)&go=([^&\s]+) [NC]
RewriteRule ^ %{REQUEST_URI}?keywords=%1+%2&go=%4 [NC,L,R]

注意:重定向指令的舊路徑性能不支持查詢字符串,這就是您上次嘗試失敗的原因。 您可以使用%{QUERY_STRING}或%{THE_REQUEST}變量來匹配帶有查詢字符串的網址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM