-1

我需要一些帮助来编写动态规则,我可以在其中添加由“/”分隔的名称/值对,而不是 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

等等。任何人都可以向我指出一些好的文档吗?

谢谢

4

1 回答 1

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

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

于 2013-01-07T13:39:43.110 回答