简体   繁体   English

重定向WordPress搜索中的某些查询词

[英]Redirect if certain query term in WordPress Search

I have a WordPress website and I want to redirect users if they search a specific term using the WordPress search functionality. 我有一个WordPress网站,如果用户使用WordPress搜索功能搜索特定术语,我想重定向用户。

If users types "mouse" in the search box, WordPress will open this page: 如果用户在搜索框中键入“鼠标”,则WordPress将打开此页面:

example.com/?s=mouse

and only if the query term is "mouse" , I want to redirect the user to: 并且仅当查询词为“ mouse”时 ,我才要将用户重定向到:

example2.com/bad.htm

If the query term is another word (eg cat), just use the default behaviour (show the search results). 如果查询词是另一个词(例如cat),则使用默认行为(显示搜索结果)。

I've tried a default redirect using .htaccess: 我尝试使用.htaccess进行默认重定向:

Redirect 301 /?s=mouse http://www.example2.com/bad.htm

But I still see /?s=mouse page and I'm not redirected. 但是我仍然看到/?s=mouse页面,并且没有被重定向。

Any solutions? 有什么办法吗?

Try below rule, 尝试以下规则,

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(s=mouse|s=mouse\+dog)$
RewriteRule ^ http://example2.com/bad.htm? [R=301,L]

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

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