通过重定向 htaccess 追加查询字符串


Appending query string through redirect htaccess

>我正在尝试在htaccess中创建重写cond我正在尝试重定向

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

或者如果可能的话,从任何搜索查询中删除"+卡片"一词......

到目前为止我尝试过什么

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]

注意:重定向指令在其旧路径perameter中不支持查询字符串,这就是您上次尝试失败的原因。可以使用 %{QUERY_STRING} 或 %{THE_REQUEST} 变量与具有查询字符串的 url 进行匹配。