marya
marya

Reputation: 157

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.

If users types "mouse" in the search box, WordPress will open this page:

example.com/?s=mouse

and only if the query term is "mouse", I want to redirect the user to:

example2.com/bad.htm

If the query term is another word (e.g. cat), just use the default behaviour (show the search results).

I've tried a default redirect using .htaccess:

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

But I still see /?s=mouse page and I'm not redirected.

Any solutions?

Upvotes: 1

Views: 221

Answers (1)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try below rule,

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

Upvotes: 2

Related Questions