【问题标题】:Htaccess Rewrite for name/value pair [closed]名称/值对的 Htaccess 重写 [关闭]
【发布时间】:2013-01-07 13:26:59
【问题描述】:

我需要一些帮助来编写动态规则,我可以在其中添加由“/”分隔的名称/值对,而不是 name1=value&name2=value2

例如

http://www.example.com/jeans.html?color=24&manufacturer=3 http://www.example.com/jeans/color/black/manufacturer/jonh-miller.html

&

http://www.example.com/jeans.html?color=24&manufacturer=3&size=1 http://www.example.com/jeans/color/black/manufacturer/jonh-miller/size/xl.html

等等。 谁能给我一些好的文档?

谢谢

【问题讨论】:

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


    【解决方案1】:

    使用 RewriteMap

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap

    你应该先匹配参数然后使用地图,例如:

    RewriteMap my_redir_map1 txt:map_rewrite.txt
    RewriteMap my_redir_map2 txt:map_rewrite.txt
    
    RewriteCond %{QUERY_STRING} ^.*(\bcolor\b=(\w+|&\w+;)+)
    RewriteCond %{QUERY_STRING} ^.*(\bmanufacturer\b=(\w+|&\w+;)+)
    RewriteRule ^/([^/\.]+).html /$1/color/${my_redir_map1:%1}/manufacturer/${my_redir_map2:%2}.html  [L]
    

    这应该匹配大小写:

    http://www.example.com/jeans.html?color=24&manufacturer=3

    并将其重写为:

    http://www.example.com/jeans/color/black/manufacturer/jonh-miller.html

    请注意:此解决方案需要为每个参数映射并为每个最终路径重写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-06
      • 2013-07-11
      • 2013-08-02
      • 2021-12-23
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 2012-01-12
      相关资源
      最近更新 更多