title: How to get nginx to do a redirect to url-encoded query parameter
body: <p>I have a requirement to do a proxy call to url delivered via a query parameter as per example:
  My nginx proxy is deployed at: <code>https://myproxy.net</code></p>
  <p>if the redirect parameter is not url encoded I can do the call with this block:</p>
  <pre><code>  location /basepath {
          if ( $arg_redirect = '') { 
            return 400 &quot;Missing redirect directive in request&quot;; 
          }
          proxy_pass $arg_redirect;
          proxy_intercept_errors on;
          error_page 301 302 307 = @handle_redirects;
      }
  
  </code></pre>
  <p>the error intercepts and @handle_redirects then take care of othe 30X codes that might pop up at new destination.<br />
  This works for a request:<br />
  <code>GET</code>: <code>https://myproxy.net/basepath?redirect=https://destination.com/somepath/uuid</code></p>
  <p>What do I need to do to make it work for:<br />
  <code>GET</code>: <code>https://myproxy.net/basepath?redirect=https%3A%2F%2Fdestination.com%2Fsomepath%2Fuuid</code></p>
  <p>Additionally as part of spec it has to be pure nginx, not additional modules, lua etc.
  Thanks!</p>