0

I have a problem with htaccess rewrite_mode. when i use multiple $_GET variables in these rules, first variable get the name file that be first $_GET variable. please help me.

RewriteEngine on
RewriteBase   /ts/
RewriteRule     ^(.+)/$                  ts.php?a=$1 [C]
RewriteRule     ^(.*)/(.+)/$             ts.php?a=$1&b=$2 [C]
RewriteRule     ^(.*)/(.*)/(.+)/$        ts.php?a=$1&b=$2&c=$3 [C]
RewriteRule     ^(.*)/(.*)/(.*)/(.+)/$   ts.php?a=$1&b=$2&c=$3&d=$4 [C,L]

this is output for "localhost/ts/1/"

Array ( [a] => 1 )

this is output for "localhost/ts/1/2/"

Array ( [a] => ts.php [b] => 2 )

this is output for "localhost/ts/1/2/3/"

Array ( [a] => ts.php [b] => 2 [c] => 3 )

this is output for "localhost/ts/1/2/3/4/5/6/"

Array ( [a] => ts.php/2/3 [b] => 4 [c] => 5 [d] => 6 )
  • That's because in a .htaccess context after rewriting is done, the new URL is fed into the rewriting process _again_ - and `ts.php?a=foo` matches `^(.+)/`. You can avoid this f.e. by simply excluding physically existing files from rewriting using a `RewriteCond`. – CBroe Jun 20 '13 at 12:36

1 Answers1

1

I wouldn't use the chain flags and just reverse your RewriteRules, like:

RewriteEngine on

RewriteBase   /ts/

RewriteRule     ^(.*)/(.*)/(.*)/(.+)/$   ts.php?a=$1&b=$2&c=$3&d=$4 [L]
RewriteRule     ^(.*)/(.*)/(.+)/$        ts.php?a=$1&b=$2&c=$3 [L]
RewriteRule     ^(.*)/(.+)/$             ts.php?a=$1&b=$2 [L]
RewriteRule     ^(.+)/$                  ts.php?a=$1 [L]
NLZ
  • 935
  • 6
  • 12