本文介绍了使用mod_rewrite替换querystring参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对此进行映射:

http://www.example.com/index.php?param1=value1&param2=value2&param3=value3 (etc. ad infinitum)

http://www.example.com/index.php?param1=newvalue1&param2=value2&param3=value3 (etc.)

换句话说,只需更改查询字符串中单个参数的值即可.我知道旧值是什么,因此我尝试匹配精确的文本index.php?param1=value1并将其替换为index.php?param1=newvalue1.我似乎找不到使用mod_rewrite如何执行此操作的任何示例.任何帮助都将不胜感激.

In other words, just change the value of a single parameter in the query string. I know what the old value is, so I am trying to match the exact text index.php?param1=value1 and replace it with index.php?param1=newvalue1. I cannot seem to find any examples on how to do this using mod_rewrite. Any assistance greatly appreciated.

推荐答案

尝试以下规则:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)param1=value1(&.*)?$
RewriteRule ^index\.php$ /index.php?%1param1=newvalue1%3 [L,R=301]

这篇关于使用mod_rewrite替换querystring参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 05:04