Nifx位置块是否包含if,但else在哪里?

问题描述 投票:0回答:1

需要将带有变量的网址重定向到另一个域名。以下代码在匹配时有效,但在不匹配时失败。

例如,当请求为https://old.example.com/test/place?id=2时,它可以工作

当请求https://old.example.com/test/place?id=1时失败

需要https://old.example.com/test/place?id=1才能通过,仅捕获id = 2。

配置中缺少什么?我想念什么?

    location = /test/place {
            if ($request_uri ~ ^/test/place\?id=2) {
                    return 301 https://new.example.com/test/place?id=2;
            }
    }
nginx-location nginx-config
1个回答
0
投票

在Nginx邮件列表成员Patrick的帮助下找到了解决方案。这是对话的链接。

The mailing list link to the solution

最终解决方案如下。

        if ( $request_uri = "/test/place?id=2" ) {
            rewrite ^ https://new.example.com${uri}?${args}? last;
    }
© www.soinside.com 2019 - 2024. All rights reserved.