我在这里有一个原始网址:
/index.php?controller=controller_name&action=action_name¶m1=val1¶m2=val2
我需要一个将其转换为:
的规则/ CONTROLLER_NAME / ACTION_NAME /参数1 / VAL1 / param2的/ val2次/
问题是我不知道有多少 param , param 可能有任何名称,例如真实案例:
/构件/滤波器/位置/ US /性别/男性/年龄/ 20
感谢您的帮助!
答案 0 :(得分:0)
RewriteEngine On
# match query string in the form
# controller=controller_name&action=action_name¶m1=val1¶m2=val2
# and rewrite it to /controller_name/action_name/?param1=val1¶m2=val2
RewriteCond %{QUERY_STRING} ^controller=([^&]+)&action=([^&]+)&?(.*)$
RewriteRule .* /%1/%2?%3
# parse the query string from result of rules above
# and create "directories" from key, value pairs
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{QUERY_STRING} ^&?([^=]+)=([^&]+)&?(.*)$
RewriteRule ^(.*)$ $1/%1/%2?%3