Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use .htaccess to redirect a string?

I need to set up a redirect for several thousand always changing URLS.

FROM THIS - example.com/product?product_id=blue_alwayschanging

TO THIS - example.com/widget?product_id=blue_alwayschanging

With my limited knowledge, I'm thinking something like the below is a step in the right direction. What am I missing? It's not working.

RewriteEngine on
RedirectMatch 301 ^/product?product_id=blue_.* /widget?product_id=.*
like image 459
Bob-3543 Avatar asked Nov 20 '25 21:11

Bob-3543


1 Answers

RewriteEngine activates mod_rewrite. Whereas RedirectMatch is a mod_alias directive. RedirectMatch also does not match against the query string, but then you don't need to, since the query string simply needs to be passed onto the target unchanged.

Try replacing your current code with the following one-liner:

RedirectMatch 301 ^/product /widget
like image 151
MrWhite Avatar answered Nov 23 '25 10:11

MrWhite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!