How to replace one query string via .htaccess?

by darrion.kuhn , in category: Third Party Scripts , 3 months ago

How to replace one query string via .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 3 months ago

@darrion.kuhn 

You can use the following code in your .htaccess file to replace one query string with another:

1
2
RewriteCond %{QUERY_STRING} ^oldquery=oldvalue$
RewriteRule ^(.*)$ $1?newquery=newvalue [L,R=301]


This code will redirect any URL with the query string oldquery=oldvalue to the same URL with the query string replaced with newquery=newvalue.


Make sure to replace oldquery=oldvalue and newquery=newvalue with the actual query strings you want to replace.


Additionally, the [R=301] flag in the RewriteRule directive will perform a permanent redirect. If you want to keep the same URL in the address bar without redirection, you can remove this flag.