返回源URL中更改的数字

时间:2017-03-07 18:20:27

标签: nginx nginx-location

用户访问时:

/profile.php?mode=viewprofile&u=[NUMBER FROM 1 TO 4000]

我希望nginx返回:

/memberlist.php?mode=viewprofile&u=[SAME NUMBER]

我该怎么办?谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

问题是您需要匹配/profile.phpmode=viewprofile,这不是一般的nginx。有很多方法可以实现它。

您可以复制location ~\.php$块并在那里添加条件重定向:

location = /profile.php {
    if ($arg_mode = viewprofile) {
        return 301 /memberlist.php?$args;
    }
    ... # add location ~\.php$ stuff here
}

或者,在server块的早期检查$ request_uri(其中包含包含查询字符串的原始URI):

if ($request_uri ~ "^/profile\.php\?mode=viewprofile&") {
    return 301 /memberlist.php?$args;
}

有关使用if声明的信息,请参阅this caution