2
I have a rewrite rule I found in a very old question of the US:
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^/]+)/ $1.php?%1 [L]
This rule allows me to pass any number of variables through the URL without having to make a rule for each quantity:
/mypage/param1/val1/param2/val2/param3/val3/... --->
/mypage.php?param1=val1¶m2=val2¶m3=val3&...
Note that the first parameter passed becomes the name of the php file, the others go from two to two and become parameter and value of a variable GET.
I want the first parameter to remain the file, but the second is the value of a variable that will always have the same name:
/test/foo/bar/baz/u/e/... --->
/test.php?varfixa=foo&bar=baz&u=e&...
I use regex and I could even do that if it were only regex, but the .htacces
has some different things.
A way that can help me too would always be to send to a index.php
, but with two fixed variables:
/test/foo/bar/baz/u/e/... --->
/index.php?varfixa1=test&varfixa2=foo&bar=baz&u=e&...
What do you expect when there are an odd number of parameters?
– Mariano
Probably the worst that can happen in this case is the last variable to be empty, so I simply ignore it, or if it is necessary I display an error on the screen. Unless that odd number is 1, then I expect you to go to the page with no GET parameter
– Guilherme Pressutto