假如我们想实现根路径不跳转,其它路径跳转,则可用下面的代码:
location / {
if ($request_uri !~* "^/$") {
rewrite ^/(.*)$ $scheme://www.baidu.com/$1 permanent;
}
}
假如我们想实现只有指定路径跳转,则可用下面的代码:
# 不跳转的路径
location / {
# 不做任何处理
}
# 匹配包含特定子串的路径
location ~* /level1/leve2/user/ppty {
rewrite ^/(.*)$ $scheme://www.baidu.com/$1 permanent;
}
上面的代码实现,只有当路径中包含字符串“/level1/leve2/user/ppty”时,才进行301跳转。