title: Nginx - if $request_uri exists proxy_pass one url, otherwise another url
body: <p>I want to handle 2 cases: <code>test.example.com</code> and <code>test.example.com/ABC</code>.</p>
  <ol>
  <li><p>If the entered url is the base domain (<code>test.example.com</code>), I want to <code>proxy_pass</code> a given endpoint (Let's say <code>example.com/home</code>).</p>
  </li>
  <li><p>If <code>test.example.com/ABC</code> is given, I want to <code>proxy_pass</code> to <code>example.com/confirm/ABC</code></p>
  </li>
  </ol>
  <ul>
  <li>test.example.com = <a href="https://example.com/home" rel="nofollow noreferrer">https://example.com/home</a></li>
  <li>test.example.com/ABC = <a href="https://example.com/confirm/ABC" rel="nofollow noreferrer">https://example.com/confirm/ABC</a></li>
  </ul>
  <p>I made the (1) work like so:</p>
  <pre><code>server {
       listen 443 ssl;
       listen [::]:443 ssl;
  
       server_name test.example.com;
  
       location / {
           proxy_pass https://example.com/home;
       }
  }
  </code></pre>
  <p>But I couldn't figure out how to say &quot;If $request_uri exists, proxy_pass to different endpoint&quot;. I tried:</p>
  <pre><code>location / {
      if ($request_uri) {
         proxy_pass https://example.com/confirm/$request_uri;
      }
   
      proxy_pass https://example.com/home;
  }
  </code></pre>
  <p>How can I achieve this?</p>