title: nginx rewrite: everything but empty base url
body: <p>After about 2 hours of googling and trying various things out, I turn to you for help.</p>
  
  <p>Task:
  Rewrite the blank url to something, and everything else to something different in nginx.</p>
  
  <p>So, if I navigate to subdomain.somedomain.tld, I want to get served the index.php, and if I go to subdomain.somedomain.tld/BlAaA, I get redirected to index.php?url=BlAaA. Exceptions are files under /img, /include, and the index.php themselves. They don't get rewritten.</p>
  
  <p>The second part works already, as does the whitelist, but I can't figure out or find something to accomplish the whole idea.</p>
  
  <p>The working part:</p>
  
  <pre><code>server {
    listen       80;
    server_name  subdomain.domain.tld;
  
    location / {
      include php.conf;
      root    /srv/http/somefolder/someotherfolder/;
  
      if ( $uri !~ ^/(index\.php|include|img) ){
        rewrite /(.*) /index.php?url=$1 last;
      }
  
      index   index.php;
    }
  }
  </code></pre>
  
  <p>The answer provided by @pablo-b almost solved my problem.
  Only two problems persist with this approach: 1: PHP-FPM now needs to have the extensions of the files under /include/ (e.g. style.css, background.jpg) set in /etc/php/php-fpm.conf under security.limit_extensions. My original php.conf worked along the lines of</p>
  
  <pre><code>location ~ \.php {
      #DO STUFF
  }
  </code></pre>
  
  <p>which nginx doesn't like, since it kinda overwrites the location /index.php part from your suggestion. I can work around that, though, given enough time.</p>
  
  <p>2: $request_uri yields "/whatever", not "whatever" as value to my url= parameter. I can parse the "/" out in my php code, for sure, but my original solution didn't add the leading "/". Any elegant way to solve this?</p>