mod rewrite with a lot of parameters
I am trying to find a mod rewrite solution to my problem.
I have almost 6 parameters that i am passing to my url and i want to rewrite.
Let me demonstrate an example of 3 parameters (x,y,z)
The url is list.php?x=1&y=2&z=3 so a rule will be
RewriteRule ^list/x/([^/\.]+)/y/([^/\.]+)/z/([^/\.]+)/?$ list.php?x=$1&y=$2&z=$3
So far fine.
The really tricky part (at least for me) is that the parameters x,y,z have no predicted order so the url might be
list.php?z=2&x=4&y=9
OR
list.php?y=2&z=4&x=9
PLUS the parameters can came not all together EX
list.php?z=4
OR
list.php?x=7&z=7
OR whatever combination of 3 arguments
So for 3 arguments i have to write all possible combinations (RewriteRule)
So my htaccess is actually 7 pages with 6 parameters and if want to add one more must write the new rules and correct all others
Is there any other way to accomplish it.
FOR EXAMPLE
if mod rewrite each parameter separate but when more than one parameter come from URL to combine the rules for each parameter.
EXAMP开发者_开发技巧LE
RewriteRule parameter x rewrite to x/$1
RewriteRule parameter y rewrite to y/$2
So when both parameters come became x/$1/y/$2
OR some smart way that i dont have to write 7 pages of rules and be easier to modify
I hope its clear
Something like this should work
RewriteRule ^list/(?=(?:x/(\d+))?)(?=(?:y/(\d+))?) /list.php?x=$1&y=$2
Although it will produce empty parameters but that might be OK.
精彩评论