需要重寫nginx

需要重寫nginx

我的網址如下:

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

我需要將它們重寫為:

index/123/456/789

不使用“如果”。

到目前為止我已經嘗試過:

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

但這不起作用。有任何想法嗎?

答案1

簡而言之,如果不使用if.

長答案是正規表示式rewrite語法僅與 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;
        }
    }

相關內容