【问题标题】:GET variable after mod_rewritemod_rewrite 之后的 GET 变量
【发布时间】:2011-11-22 22:57:37
【问题描述】:

我有一组遵守以下 htaccess 规则的产品页面:

RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_URI} ^/([0-9]+)\-(.+)\.html
RewriteRule ^(.*)$ /product/index.php?prod=%1-%2 [L]

将它们重写为:example.com/123-1234.html。

我的问题是我不能再向页面传递额外的 $_GET 变量 - 即:example.com/123-1234.html?coupon=something123。

有什么办法吗?

【问题讨论】:

  • mod_rewrite 的重点是保持 url 和 uri 完整。您无法访问$_GET['prod']?另一种方法是获取 url 并使用 explode 将其拆分。

标签: php apache .htaccess mod-rewrite


【解决方案1】:

您正在寻找 QSA,查询字符串追加

RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_URI} ^/([0-9]+)\-(.+)\.html
RewriteRule ^(.*)$ /product/index.php?prod=%1-%2 [L,QSA]

【讨论】:

  • 谢谢,这正是我想要的。
  • @beaudierman:如果答案正确,别忘了接受这个答案
【解决方案2】:

添加 QSA 标志以传递现有的查询字符串参数

RewriteRule . /product/index.php?prod=%1-%2 [QSA,L]

还将匹配编辑为 .和 ^.*$ 在这种情况下是等价的

【讨论】:

    猜你喜欢
    • 2014-01-13
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 2013-01-17
    • 2010-12-02
    • 2016-05-10
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多