nginx重写正则重写root和subdirectory
目前,我有
server {
listen 8080;
server_name default;
location /foo/ {
rewrite ^/foo(/.*)$ $1 break;
proxy_redirect https://example.com https://$host/;
}
这种匹配的foo,并且基本上剥离了它。我需要维护此功能,还需要包括bar(如果是foo之后)。 IE如果URL为/foo/bar
,我希望这两个本质上都被剥离。我不太擅长于等级,并且正在努力做到这一点。
我在思考(foo)|(\/bar)
之类的东西,但不确定如何将尾随的斜线与之匹配。
Currently i have
server {
listen 8080;
server_name default;
location /foo/ {
rewrite ^/foo(/.*)$ $1 break;
proxy_redirect https://example.com https://$host/;
}
This matches foo and essentially strips it. I need to maintain this functionality, and also include bar if it is after foo. i.e. if the url is /foo/bar
I want both of those essentially stripped. I'm not great at regex and am struggling with the proper way to do this.
I'm thinking something like (foo)|(\/bar)
, but not sure how to match a trailing slash with that as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
/bar
作为可选组件添加到您的正则模式:请注意,捕获组引用已更改为
$ 2
Add
/bar
as an optional component to your regex pattern:Note that the capture group reference has been changed into
$2