如何使用其他URL变量重定向页面

时间:2014-11-04 16:34:45

标签: .htaccess mod-rewrite parameters

我想将单个页面(index.php)从旧位置(http://old.com)重定向到新位置(http://new.com)。此页面可以有各种URL参数,我需要添加一个额外的参数(例如:p = 9)。当未指定index.php时,重定向也应该有效,因为它是默认文件。

所需结果的几个例子:

http://old.com                       -> http://new.com/index.php?p=9
http://old.com/                      -> http://new.com/index.php?p=9
http://old.com/index.php             -> http://new.com/index.php?p=9
http://old.com/index.php?a=1&b=2&c=3 -> http://new.com/index.php?a=1&b=2&c=3&p=9
http://old.com/index.php?p=555       -> not important, parameter p can't be there

在对网络和各种测试进行研究后,这是我的.htaccess文件:

RewriteEngine On
RewriteRule ^/index.php(.*)$ http://new.com/index.php?p=9 [R=301,L,QSA]

不幸的是,正如我所料,它不会将现有参数与新参数合并。当没有指定index.php时,它也不起作用。

0 个答案:

没有答案