regex - nginx不区分大小写的url重定向

标签 regex redirect nginx

关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

7年前关闭。




Improve this question




我想在 nginx 中做不区分大小写的 url 重定向
下面是我的代码。

location ~* WapsiteDataFetch{
      rewrite  WapsiteDataFetch(.*) http://images.xample.com/xyz/images$1 permanent;
    }

在上述情况下,
www.example.com/WapsiteDataFetch正确重定向到 http://images.xample.com/xyz/images但是,网址 "www.example.com/WAPSITEDATAFETCH"没有正确重定向。

即使我更改了单个字符,它也会出现 404 错误。

我尝试了很多博客,看到了很多来自堆栈溢出的帖子,其中很多都建议使用“~*”,但就我而言,它对我没有帮助。

请帮助我,因为我坚持了几天。

最佳答案

使用 (?i)不区分大小写匹配 - http://perldoc.perl.org/perlretut.html

不需要位置块。尝试这个。

rewrite (?i)^/WapsiteDataFetch(.*) http://images.xample.com/xyz/images$1 permanent;

关于regex - nginx不区分大小写的url重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21577841/

相关文章:

javascript - 删除 src 匹配上的动态脚本标记

python - 具有特定值的字符串的正则表达式

powershell - 错误重定向在 powershell 中不起作用

http - 我想将所有流量重定向到 http ://www. mywebsite.com

django - 502 错误网关与 NGINX、Gunicorn、Django

python - 如何使用正则表达式将这个字符串分成两部分?

mysql - 使用正则表达式将一列拆分为多列

ubuntu - 如何使用 ssl Apache 将 www.subdomain 重定向到子域

nginx - 注释 proxy-body-size 在 kubernetes nginx-ingress 中不起作用

node.js - Nodejs 未在服务器中运行