nginx - 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;
哪个效果很好,但我很难获得以下字符串
- 正则表达式捕获的部分 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
任何帮助将不胜感激,干杯!
解决方案
推荐阅读
- java - Java许可证不用于商业用途?
- mongodb - 在同一应用程序中为同一模型和同一存储库使用多个 mongo DB
- excel - VBA Excel在另一个Excel文档中查找数字并复制特定列
- r - 安装 igraph 时未找到 sed 和 expr 且退出状态非零
- javascript - 从 React 中的对象数组中渲染一个对象
- javascript - Vuejs 事件处理程序中是否需要 $event?
- python - 使用 reticulate 包从 Python peakutils 包调用函数时出现类型错误
- css - 在 CSS GRID 布局内创建响应式行和列
- c# - 如何启动 UWP 模拟器?
- reactjs - 这两种使用打字稿创建功能组件的方法有什么区别?