mod_rewrite发送不正确的结果

时间:2013-03-05 10:15:25

标签: php mod-rewrite

我的重写规则如下:

RewriteRule ^groups/([0-9]+)/pg:([0-9]+);cr:(0|1);r:([a-z0-9-]+);rv:(0|1);eu:(0|1);fr:(0|1);de:(0|1);it:(0|1);ru:(0|1);es:(0|1);br:(0|1);la:(0|1);us:(0|1);au:(0|1)$ index.php?mod=groups&groups=$1&pg=$2&crossrealm=$3&realm=$4&reverse=$5&eu=$6&fr=$7&de=$8&it=$9&ru=$10&es=$11&br=$12&la=$13&us=$14&au=$15 [NC,L]

重定向哪个成功,但发送的$_GET显示错误的结果:

$_GET:
array (size=16)
  'mod' => string 'groups' (length=6)
  'groups' => string '117' (length=3)
  'pg' => string '1' (length=1)
  'crossrealm' => string '1' (length=1)
  'realm' => string 'aegwynn' (length=7)
  'reverse' => string '0' (length=1)
  'eu' => string '1' (length=1)
  'fr' => string '0' (length=1)
  'de' => string '0' (length=1)
  'it' => string '0' (length=1)
  'ru' => string '1170' (length=4)
  'es' => string '1171' (length=4)
  'br' => string '1172' (length=4)
  'la' => string '1173' (length=4)
  'us' => string '1174' (length=4)
  'au' => string '1175' (length=4)

是否有人有任何想法可能导致此问题及其解决方法?

EDIT:错误从mod_rewrite部分开始,该部分从$10开始,即&ru=。重写的URL正确返回,但实际的URL是http://localhost/index.php?mod=groups&groups=117&pg=1&crossrealm=1&realm=aegwynn&reverse=0&eu=1&fr=0&de=0&it=1&ru=1170&es=1171&br=1172&la=1173&us=1174&au=1175

1 个答案:

答案 0 :(得分:2)

mod-rewrite不允许您捕获超过9个参数(从$1$9)。

在您的情况下,$10被视为($1)0,这就是您获得'1170'的原因。

您最好发送整个请求的URI并使用PHP将其展开:

  list(
    $_GET['mod'], 
    $_GET['groups'], 
    $_GET['pg'], 
    $_GET['crossrealm'], 
    $_GET['realm'], 
    $_GET['reverse'], 
    $_GET['eu'], 
    $_GET['fr'], 
    $_GET['de'], 
    $_GET['it'], 
    $_GET['ru'], 
    $_GET['es'], 
    $_GET['br'], 
    $_GET['la'], 
    $_GET['us'], 
    $_GET['au']
  ) = explode( '/', $_GET['params']);