Php htaccess将动态URL重定向到另一个动态URL

Php htaccess将动态URL重定向到另一个动态URL,php,regex,.htaccess,mod-rewrite,redirect,Php,Regex,.htaccess,Mod Rewrite,Redirect,我需要将一个动态URL重定向到另一个,但参数略有改变。这是原始URL: http://www.EXAMPLE.com/index.php?main_page=index&cPath=5 它需要重定向到 http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 我尝试过这么多不同的变化,但似乎没有一个是有效的 RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5

我需要将一个动态URL重定向到另一个,但参数略有改变。这是原始URL:

http://www.EXAMPLE.com/index.php?main_page=index&cPath=5
它需要重定向到

http://www.EXAMPLE.com/index.php?main_page=index&cPath=25
我尝试过这么多不同的变化,但似乎没有一个是有效的

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$
RewriteRule ^/(index\.php|)$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [L,R=301]

我要为这个发疯了。。。谁能给我指出正确的方向,告诉我我做错了什么吗?

也许没有条件

RewriteEngine on
rewriterule ^index.php?main_page=index&cPath=5$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [r=301,nc]

我相信在你的模式中,前导斜杠是个问题。在根目录中尝试此规则。htaccess:

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$ [NC]
RewriteRule ^/?(index\.php)?$ /$1?main_page=index&cPath=25 [NC,L,R=301]

查询字符串在RewriteRule中不可用,因为RewriteRule处理路径,所以应该使用RewriteCond。啊,这是一个非常漂亮的解决方案,非常感谢!