title: Nginx redirect with regex
body: <p>Hi I'm having trouble with setting up nginx and redirecting with regex</p>
  <p>What's expected is :</p>
  <p><strong><a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a></strong> =&gt; it redirects to ip 11.11.11.11</p>
  <p><strong><a href="http://www.example.com/test" rel="nofollow noreferrer">www.example.com/test</a></strong> =&gt; it redirects to ip 22.22.22.22</p>
  <p><strong><a href="http://www.example.com/api" rel="nofollow noreferrer">www.example.com/api</a></strong> =&gt; it redirects to ip 33.33.33.33</p>
  <p>I tried this, but idont know what im doing wrong</p>
  <pre><code>location / {
                rewrite ^/(?:test)/(.*)$ http://22.22.22.22/$1 break;
                rewrite ^/(?:api)/(.*)$ http://33.33.33.33/$1 break;
                proxy_pass              http://11.11.11.11/;
          }
  </code></pre>
  <p>And with the config below
  When I open <strong><a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a></strong> first if I try to access <strong><a href="http://www.example.com/test" rel="nofollow noreferrer">www.example.com/test</a></strong> it shows the production site (<strong><a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a></strong>)</p>
  <pre><code>location / {
                proxy_pass              http://11.11.11.11/;
          }
  
  location ^~ /test/  {
                proxy_pass              http://22.22.22.22/;
          }
  
  location ^~ /api/ {
                proxy_pass              http://33.33.33.33/;
          }
  </code></pre>
  <p><strong>Help Please !!</strong></p>