nginx 重写规则以重写某个正则表达式的每个匹配,除了 [英] nginx Rewrite Rules to Re-write Every Match Of a Certain Regex Except
本文介绍了nginx 重写规则以重写某个正则表达式的每个匹配,除了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 nginx 中编写重写规则.
I'm writing rewrite rules in nginx.
我想将每个匹配 /A/B[anything]
的 URI 重写为 /X/
except /A/B/C[/]
.
I want to rewrite every URI that matches /A/B[anything]
to /X/
except /A/B/C[/]
.
我该怎么做?
我尝试过的:
if ($request_uri ~ ^/A/B/C/?) {
break;
}
rewrite ^/A/B /X/ permanent;
这将 /A/B
重写为 /X/
,但是 /A/B[anything]
不会被重定向,也不会被重定向/A/B/C/
是否留在 /A/B/C/
.
This rewrites /A/B
to /X/
, but /A/B[anything]
doesn't get redirected, nor does /A/B/C/
stay at /A/B/C/
.
推荐答案
我发现了这个问题.
我需要重写一行
rewrite ^/A/B(.*)? /X/ permanent;
(.*)?
的意思是并且可以任意匹配任意次数."
The (.*)?
means " and optionally match anything any amount of times."
这篇关于nginx 重写规则以重写某个正则表达式的每个匹配,除了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文