用户访问时:
/profile.php?mode=viewprofile&u=[NUMBER FROM 1 TO 4000]
我希望nginx返回:
/memberlist.php?mode=viewprofile&u=[SAME NUMBER]
我该怎么办?谢谢你的帮助。
答案 0 :(得分:1)
问题是您需要匹配/profile.php
和mode=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。