需要重写nginx

我有像这样的url:

index.php?q=123&w=456&e=789 

我需要重写他们的东西,如:

 index/123/456/789 

而不使用“如果”。

到目前为止我已经尝试过:

 location / { rewrite ^/index.php\?q=(.*)&w=(.*)&e=(.*)$ /index/$1/$2/$3; } 

但它不起作用。 有任何想法吗?

简短的答案是你不能没有使用if

长的答案是在rewrite语法中的正则expression式只匹配URI。

尝试这样的事情:

  location /index.php { if ($args ~ "^q=(.*)&w=(.*)&e=(.*)") { set $arg_q $1; set $arg_w $2; set $arg_e $3; rewrite_log on; rewrite ^ /index/$arg_q/$arg_w/$arg_e last; } }