如何实现 Nginx 不区分大小写的目录位置重定向 301 [英] How to implement Nginx case-insensitive directory-location redirection 301

查看:108
本文介绍了如何实现 Nginx 不区分大小写的目录位置重定向 301的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想http://example.com/SomeThing重定向到http://example.com/something

something 是 nginx 位置(/something)目录

请建议如何实现不区分大小写的目录位置重定向

推荐答案

我假设 http://example.com/something 不会被重定向.因此,对区分大小写的匹配使用前缀位置,并使用 ^~ 修饰符跳过检查正则表达式:

I'm assuming that http://example.com/something would not be redirected. So use a prefix location for the case sensitive match with the ^~ modifier to skip checking regular expressions:

location ^~ /something {
    return 200 "case sensitive something match
";
}

现在为重定向添加不区分大小写的正则表达式位置:

Now add the case insensitive regular expression location for the redirect:

location ~* ^/something {
    return 301 $scheme://$host/something;
}

这篇关于如何实现 Nginx 不区分大小写的目录位置重定向 301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆