title: Removing only a specific URL parameter in Nginx with rewrite
body: <p>I'm trying to make Nginx remove only a specific parameter from the requested URL. Let's say that the parameter name is <code>par2</code>. Here are the examples of requested URLs:</p>
  
  <pre><code>www.example.com/page?par1=a&amp;par2=b
  www.example.com/page?par2=b
  </code></pre>
  
  <p>Those pages should redirect to:</p>
  
  <pre><code>www.example.com/page?par1=a
  www.example.com/page
  </code></pre>
  
  <p>Here is what I have in conf file at the moment:</p>
  
  <pre><code>location / {
      ...
      if ($args ~* "par2") {
          rewrite ^(.*)$ $request_uri permanent;
      }
  }
  </code></pre>
  
  <p>This partly works - it does remove <code>par2</code> parameter, but it removes all of the other parameters as well and redirects to:</p>
  
  <pre><code>www.example.com/page
  www.example.com/page
  </code></pre>
  
  <p>How to make it remove only a specific parameter (<code>par2</code> in this case)?</p>
  
  <p>EDIT:
  As far as I know, it's recommended to use <code>if</code> only if it's followed by <code>rewrite</code>, so I'd prefer such a solution.</p>