0

Here I have an original url:

/index.php?controller=controller_name&action=action_name&param1=val1&param2=val2

I need a rule that will transform it to:

/controller_name/action_name/param1/val1/param2/val2/

The issue is I don't know how many param out there, param may have any name, for example a real case:

/member/filter/location/us/gender/male/age/20

Thanks for your help!

4

1 回答 1

0
RewriteEngine On
# match query string in the form
#  controller=controller_name&action=action_name&param1=val1&param2=val2
# and rewrite it to /controller_name/action_name/?param1=val1&param2=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
于 2012-11-20T13:14:12.210 回答