【问题标题】:Rewrite rule needed for various querystring combinations各种查询字符串组合所需的重写规则
【发布时间】:2011-12-08 18:03:47
【问题描述】:

我需要使用htaccess重写一个规则,我目前有以下:

RewriteRule ^test/example/(.*)/(.*)/(.*)/example\.html$ test/example/example/index.php?s=$1&t=$2&p=$3  [L]

从以下位置重写网址:

test/example/example/index.php?s=Red&t=Audi&p=Petrol

test/example/Red/Audi/Petrol/example.html

这可行,但我希望该规则适用于以下 3 个条件:

  1. 查询字符串中没有值,因此只需转到 url:test/example/example.html

  2. 查询字符串中的“s”有一个值,然后重写规则将用户发送到:test/example/Red/example.html

  1. 三个变量都有值,然后 url 转到:test/example/Red/Audi/Petrol/example.html

谢谢

【问题讨论】:

    标签: php .htaccess url-rewriting


    【解决方案1】:

    依次添加三个重写规则:

    RewriteRule ^test/example/(.*)/(.*)/(.*)/example\.html$ test/example/example/index.php?s=Red&t=Audit&p=Petrol
    RewriteRule ^test/example/(.*)/example\.html$ test/example/example.html?s=Red
    RewriteRule ^test/example/example\.html$ test/example/example.html
    

    一切都完成了。

    【讨论】:

    • 你对正则表达式有多大的耐心? :P 非常好。
    • 我以编写编译器为生 :) 所有正则表达式都是私人朋友
    • 谢谢,我应该猜到了! :)
    猜你喜欢
    • 2016-08-13
    • 2016-11-01
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2012-03-08
    • 1970-01-01
    • 2016-12-08
    相关资源
    最近更新 更多