.htaccess rewriterule保留参数

时间:2014-06-25 18:12:13

标签: php apache .htaccess mod-rewrite get

我目前在.htaccess文件中有这一行:

RewriteRule ^(20\d\d)/([A-Za-z0-9-]+)/$ /test/?type=post&year=$1&title=$2 [L]

它允许这样的网址:

/test/?type=post&year=2014&title=hello

可以像这样访问:

/test/2014/hello/

但是,有时我在重写的URL上有另一个GET变量:

/test/2014/hello/?page=2

但是,页面上的PHP文件无法读取get变量page。换句话说,如何更改我的.htaccess文件以允许其他获取变量(添加到重写的URL)以供PHP文件使用和读取?

1 个答案:

答案 0 :(得分:2)

您需要在重写规则中添加QSA标志,以便括号如下所示:

[L,QSA]

这告诉apache将任何现有的查询字符串附加到目标中的新查询字符串(mode = allBrands)。

更多信息:http://wiki.apache.org/httpd/RewriteFlags/QSA

相关问题