【问题标题】:.htaccess rewriterule keep parameters.htaccess rewriterule 保留参数
【发布时间】:2014-08-16 10:19:00
【问题描述】:

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

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

它允许这样的 URL:

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

访问方式如下:

/test/2014/hello/

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

/test/2014/hello/?page=2

但是,页面上的 PHP 文件不会读取 get 变量 page。所以换句话说,我怎样才能改变我的 .htaccess 文件以允许 PHP 文件使用和读取其他 get 变量(添加到重写的 URL)?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite get


    【解决方案1】:

    您需要在重写规则中添加一个 QSA 标志,以便括号看起来像这样:

    [L,QSA]
    

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

    更多信息:https://cwiki.apache.org/confluence/display/HTTPD/RewriteFlags+QSA

    猜你喜欢
    • 2011-05-03
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多