为什么 nginx 将 zh_cn 重定向到 zh_cn/?

Why nginx redirect zh_cn to zh_cn/?

我写的nginx配置文件如下,当我输入url http://xxx/zh_cn, it will redirect to http://xxx/zh_cn/时,但是如果我删除"if (-d $request_filename){}",nginx不会重定向路径,为什么?

location = / {
    if ($http_accept_language ~* ^zh-cn) {
        set $lang zh_cn;
        rewrite ^/$ /$lang/index.html redirect;
    }
}

location / {
   if (-d $request_filename){}
   try_files $uri $uri/index.html $uri.html /abc/$uri;
}

我知道代码 "rewrite ^/(.*)([^/])$ http://$host// permanent" 可以重定向路径,但为什么 "if (-d $request_filename){}" 也可以?

来自 If is evil 的第三个示例。

在这种情况下,您的 try_files 将被忽略,如果 nginx 发现不带斜线的请求与目录匹配,则它的默认行为会重定向到带有斜线的 URL。