I got this working snippet to change a query parameter:
RewriteCond %{QUERY_STRING} (.*)&?name=(.*)? [NC]
RewriteRule ^pokladna/?$ $0?%1name_gls=%2 [R=301,L]
from here .htaccess rewrite rule with string replacement in url
But in my case I need to replace multiple query parameters.
For example: https://example.com/?utm_source=source&utm_medium=banner&utm_campaign=campaignname
needs to be https://example.com/?mtm_source=source&mtm_medium=banner&mtm_campaign=campaignname
There might be other parameters before, after or in between, which should not be affected.
Thank you!
2
Answers
With your shown samples, attempts please try following htaccess rules file. Please make sure to clear your browser cache before testing your URLs.
Generic solution:
Here is how you can replace multiple query parameters that start with
utm_
to their counterparts that start withmtm_
:Once satisfied with the result replace
302
with301
(permanent redirect).This needs to be tested on a local Apache web server not on any online test facility.