Changing query string key name with htaccess rewrite rule

烈酒焚心 提交于 2021-01-20 13:15:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/50665743/changing-query-string-key-name-with-htaccess-rewrite-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!