【问题标题】:Rewriting URLs and allowing multiple Query Strings重写 URL 并允许多个查询字符串
【发布时间】:2011-09-15 23:03:06
【问题描述】:

我想重写 URL,同时仍然允许多个可选的查询字符串。

例如,我知道我可以这样做:

RewriteCond %{QUERY_STRING} ^page=(\d+)$
RewriteRule ^products/?$ products.php

是否可以允许传递更多查询字符串,以便我可以使用 products/?page=1&foo=bar 之类的东西?

谢谢。

编辑:我想要的只是规则末尾的 [QSA]。像我预期的那样工作。

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    你可以这样做:

    RewriteCond %{QUERY_STRING} ^page=[0-9]*&foo=bar$
    RewriteRule ^products/?$ products.php [L]
    

    或者像这样简单地重写你的条件:

    RewriteCond %{QUERY_STRING} (^|&)page=[0-9]*(&|$)
    RewriteRule ^products/?$ products.php [L]
    

    【讨论】:

    • 感谢您的帮助,但不是我想要的。我刚刚发现我可以在规则末尾添加 [QSA] 并且它可以按预期工作。还是谢谢!
    猜你喜欢
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多