简体   繁体   English

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

[英]Appending query string through redirect htaccess

I am trying to create a rewrite cond in htaccess I am trying to redirect 我试图在htaccess中创建一个重写条件,我试图重定向

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

to

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

or if possible remove the word "+cards" from any search queries... 或者,如有可能,从任何搜索查询中删除“ + cards”一词...

what I have tried so far 到目前为止我尝试过的

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

also tried 也尝试过

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

and this 和这个

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

None of these working... is it possible? 这些都不起作用...有可能吗? Can any one help? 有人可以帮忙吗? Thank You in advance 先感谢您

Try the following code : 试试下面的代码:

RewriteEngine On

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

Another solution 另一种解决方案

RewriteEngine On

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

Note : Redirect directive does not support querystrings in its old path perameter, that is why your last attempt failed. 注意:重定向指令的旧路径性能不支持查询字符串,这就是您上次尝试失败的原因。 You can use %{QUERY_STRING} or %{THE_REQUEST} variable to match against urls with query strings. 您可以使用%{QUERY_STRING}或%{THE_REQUEST}变量来匹配带有查询字符串的网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM