1

I want to redirect to one query string URL to another:

example.com/product-category/search/?filter_grade-level=154

to

example.com/product-category/search/?filter_grade-level=k

Any thoughts what to add in .htaccess?

MrWhite
  • 11,643
  • 4
  • 25
  • 40
speedwheel
  • 11
  • 1
  • Check http://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever out. – Tero Kilkanen Apr 12 '17 at 15:10
  • Possible duplicate of [Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod\_Rewrite Rules but Were Afraid to Ask](http://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever) – Jenny D Apr 12 '17 at 15:38

1 Answers1

0

You need to use mod_rewrite to check the query string. Try something like the following at the top of your `.htaccess file:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(filter_grade-level)=154$
RewriteRule ^product-category/search/$ /$0?%1=k [R=301,L]

In the RewriteRule substitution (ie. /$0?%1=k), $0 is a backreference to the entire matched RewriteRule pattern and %1 is a backreference to the captured group in the last matched CondPattern (ie. "filter_grade-level").

So, on success, /$0?%1=k expands to:

/product-category/search/?filter_grade-level=k
MrWhite
  • 11,643
  • 4
  • 25
  • 40