例如,我想这样做:
if ($http_user_agent ~ "MSIE 6.0" || $http_user_agent ~ "MSIE 7.0" (etc, etc)) {
rewrite ^ ${ROOT_ROOT}ancient/ last;
break;
}
而不是这个:
if ($http_user_agent ~ "MSIE 6.0") {
rewrite ^ ${ROOT_ROOT}ancient/ last;
break;
}
if ($http_user_agent ~ "MSIE 7.0") {
rewrite ^ ${ROOT_ROOT}ancient/ last;
break;
}
Nginx 拒绝这种语法(减去(等等)),并且我在文档中没有看到任何关于此的内容。
另外,我们选择不使用 $ancient_browser 指令,因此这不是一个选项。
Edit:
由于 Alexey Ten 没有添加新答案,因此我将编辑我的答案,以在这种情况下给出他更好的答案。
if ($http_user_agent ~ "MSIE [67]\.")
原答案:
Nginx 不允许使用多个或嵌套的 if 语句,但是您可以这样做:
set $test 0;
if ($http_user_agent ~ "MSIE 6\.0") {
set $test 1;
}
if ($http_user_agent ~ "MSIE 7\.0") {
set $test 1;
}
if ($test = 1) {
rewrite ^ ${ROOT_ROOT}ancient/ last;
}
它并不短,但它允许您进行检查并仅将重写规则放置一次。
替代答案:
在某些情况下,您还可以使用 | (管道)
if ($http_user_agent ~ "(MSIE 6\.0)|(MSIE 7\.0)") {
rewrite ^ ${ROOT_ROOT}ancient/ last;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)