title: How to remove a subdirectory from the url before passing to a script?
body: <p>This has been asked on <a href="https://stackoverflow.com/questions/20453205/nginx-rewrite-url-removing-subfolder">SO before</a> but the answers have not been generalized. So here goes.</p>
  
  <p>I have two different web apps.  They were made to be on different servers at the root.  But now they are going to be placed into subdirectories on the same server.  The script below is sending the subdirectory along with the URI's to the scripts.  This is a problem.</p>
  
  <p>old urls:</p>
  
  <ul>
  <li><a href="http://store.example.com/items/1" rel="noreferrer">http://store.example.com/items/1</a></li>
  <li><a href="http://backoffice.example.com/accounts/1234" rel="noreferrer">http://backoffice.example.com/accounts/1234</a></li>
  </ul>
  
  <p>new urls:</p>
  
  <ul>
  <li><a href="http://www.example.com/store/items/1" rel="noreferrer">http://www.example.com/store/items/1</a></li>
  <li><a href="http://www.example.com/backoffice/accounts/12345" rel="noreferrer">http://www.example.com/backoffice/accounts/12345</a></li>
  </ul>
  
  <p>The store site is seeing <code>/store/items/1</code> when it wants to just see <code>/items/1</code>.  The same goes for the backoffice site.</p>
  
  <p>My attempt:</p>
  
  <pre><code>    location /store {
              try_files @store_site;
      }
  
      location /backoffice {
              try_files @backoffice_site;
      }
  
      location @store_site {
              include uwsgi_params;
              uwsgi_pass unix:/var/run/uwsgi/store_site.sock;
              proxy_set_header Host $host;
      }
  
      location @backoffice_site {
              include uwsgi_params;
              uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;
              proxy_set_header Host $host;
      }
  </code></pre>
  
  <p>Again, the store site is getting URLs with the <code>/store</code> prefix and backoffice is getting <code>/backoffice</code>.  Those sites were coded to not expect those prefixes.  I need to remove the <code>/store</code> and <code>/backoffice</code> prefix before sending to the actual site.</p>
  
  <p>Is this a rewrite rule thing?</p>
  
  <p>I tried this based on <a href="https://stackoverflow.com/questions/13539246/nginx-rewrite-rule-with-proxy-pass">this SO page</a> and it didn't work.  I must not understand something about the syntax.</p>
  
  <pre><code>location /store {
          rewrite  ^/store/(.*) /$1;
          try_files $uri @store_site;
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Apparently, this works (added <code>break;</code>)  Is this a complete solution?</p>
  
  <pre><code>location /store {
          rewrite  ^/store/(.*) /$1 break;
          try_files $uri @store_site;
  }
  </code></pre>