首页 > 解决方案 > Nginx 映射重定向捕获正则表达式/查询字符串捕获并重定向到新的

问题描述

我正在尝试使用 map 指令在 nginx(openresty) 中设置批量重定向,但在从源 url 捕获正则表达式/查询字符串并转发到目标 url 时遇到了一些问题。下面就像我的设置

nginx.conf 就像

map_hash_bucket_size 512;
map_hash_max_size 32768;
map $uri $new_redirects {
  default "none";
  include /usr/local/openresty/nginx/conf/new_redirect.map;
   }

服务器块

if ($new_redirects != "none") {
   return 301 $scheme://$http_host$new_redirects;
   }

新的重定向地图包含以下重定向

~^/test/123/(\w+)(\w+).*$ /US/en/test/$1-$2;

哪个效果很好,但我很难获得以下字符串

  1. 正则表达式捕获的部分 url

/Product.html?ProdNo=A5441&Brand=COMPANY

在新 url 中捕获

/US/en/product/COMPANY-A5441

2.Regex Capture的部分url

/ProductDetail.do?&N5=SEARCH_CONCAT_PNO|BRAND_KEY&F=SPEC&N4=AV35016|COMPANY

在新 url 中捕获

/US/en/product/COMPANY-AV35016

任何帮助将不胜感激,干杯!

标签: nginxredirectnginx-module

解决方案


推荐阅读