Search code examples
.htaccessjoomlaurl-rewritingquery-string

Changing query string key name with htaccess rewrite rule


We are changing affiliate software and I can't figure out how to rewrite the name of the query string key to achieve the following:

https://www.example.com/path/to/productx?old_key_name=numeric_value

Redirect to:

https://www.example.com/path/to/productx?new_key_name=numeric_value

So far I have:

RewriteCond %{QUERY_STRING} ^old_key_name=([0-9]+)

RewriteRule ^ %{REQUEST_URI}?new_key_name=%1 [L,R=301]

Which doesn't retain the full path to the product, but results in:

https://www.example.com/index.php?new_key_name=numeric_value

/path/to/productx/ is missing.

I'm placing the rule at the bottom of a Joomla htaccess file on an Apache server. Can the full path to the product be added to the redirect rule?


Solution

  • I've just moved the rule to the top of the htaccess file and it works as expected. I guess the default Joomla SEF Rewrite rules were the problem.