如何匹配”?“Nginx中的字符重写

pgx2nnw8  于 2023-06-05  发布在  Nginx
关注(0)|答案(1)|浏览(133)

当我访问http://localhost/bill/detail/123?a=1&b=2
我希望它重定向到https://www.baidu.com/bill/detail/?a=1&b=2&term=123
下面是我的配置:

location /bill/detail {
    rewrite  ^/bill/detail/([\d]+)\?(.*)$ https://www.baidu.com?$2&term=$1 redirect;
  }

但显示不匹配

2023/06/03 20:20:38 [notice] 3128#0: *5 "^/bill/detail/([\d]+)\?(.*)$" does not match "/bill/detail/1234", client: 127.0.0.1, server: 127.0.0.1, request: "GET /bill/detail/1234?a=1&b=2 HTTP/1.1", host: "localhost:5000"
wn9m85ua

wn9m85ua1#

对于您的请求,请尝试以下操作:

location ~ /bill/detail/(?<term>\d+).*$ {
  return 301 http://www.domain.tld?a=$arg_a&b=$arg_b&term=$term;
}

相关问题