Nginx map redirect capture regex/query string capture and redirect to new

554 views Asked by At

I am trying to setup bulk redirections in nginx(openresty) with map directive but am facing some issues with capturing regex/query string from the source url and forward to destination url. below is like my setup

nginx.conf is like

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;
   }

Server Block

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

new redirect map contains below redirects

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

Which is working good but i am struggling a lot to get for the below strings

  1. Part of url for Regex Capture

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

Captures in the new url

/US/en/product/COMPANY-A5441

2.Part of url for Regex Capture

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

Captures in the new url

/US/en/product/COMPANY-AV35016

Any help would be greatly appreciated, Cheers all!

0

There are 0 answers