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