URL动态参数重写 [英] URL rewriting with dynamic parameters
本文介绍了URL动态参数重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能重写URL,以形成GET参数,如果参数的数量和名称没有在第一位置设置?
Is it possible to rewrite URL to form with GET parameters if the count and name of parameters is not set in the first place?
让我们说我有这个
/categories/key_1/111/
/categories/key_1/111/key_2/222/
/categories/key_1/333/key_2/444/key_3/555/
/categories/key_5/333/key_6/444/key_7/555/
我可以改写这形成的?
Can I rewrite this to form?
/categories/?key_1=111&key_2=222....&key_x=xxx
如果订单,数量和参数名称的不是静态的
if the order, amount and name of parameters is not static
唯一的条件是,的key-value 的对是这样设置
The only condition is that KEY-VALUE pair is set like this
/ ROOT_FOLDER / key_x / value_x /
/root_folder/key_x/value_x/
推荐答案
这单递归应该是能够做到这一点:
This single recursive should be able to do that:
RewriteEngine On
# to convert /categories/n1/v1/n2/v2 to /categories/?n2=v2&n1=v1
RewriteRule ^(categories)/([^/]*)/([^/]*)(/.*)?$ /$1/$4?$2=$3 [L,QSA,NC]
这篇关于URL动态参数重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文