How to replace one query string via .htaccess?

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

How to replace one query string via .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 6 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.

Related Threads:

How to query from one to many tables in mysql?
How to replace more than one character in oracle?
How to replace one git branch with another?
How to replace string before string using regex?
How to replace string by regex?
How to replace request param name using .htaccess?