首页 > 解决方案 > 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?

标签: .htaccessjoomlaurl-rewritingquery-string

解决方案


我刚刚将规则移到 htaccess 文件的顶部,它按预期工作。我猜默认的 Joomla SEF 重写规则是问题所在。


推荐阅读