As some background, I'm trying to fix requests that are coming in with duplicated params e.g:
/products/compare/?ids=554?ids=554
/products/compare/?ids=595,662,726?ids=595,662,726
My fix - which works - looks like this:
location /products/compare/ {
if ( $args ~ "(ids=[\d,]+)\?ids=[\d,]+" ) {
set $id $1;
rewrite ^.*$ $scheme://$host/$uri$is_args$id? permanent;
}
}
My question is regarding the set $id $1;, and why it's necessary
I was using the $1 capture-group variable directly in the rewrite:
rewrite ^.*$ $scheme://$host/$uri$is_args$1? permanent;
But the variable wasn't being populated.
Why not?