title: nginx rewrite condition only for root folder (not for subfolders)
body: <p>I'm using nginx infront of apache for static content serving. I have a rewrite rule, which redirects all missing php files to specific (index.php) file. But currently that rule applies everywhere in the root folder (including subdirectories). I want to make it working only for / directory and not subdirectories. For example if I access <a href="http://www.domain.com/someting/missing.php" rel="nofollow">http://www.domain.com/someting/missing.php</a> I want to get 404 code. But if I access <a href="http://www.domain.com/missing.php" rel="nofollow">http://www.domain.com/missing.php</a> still to get index.php<br>
  Here is my code so far :</p>
  
  <pre><code>location ~ \.php$ {
  proxy_pass http://ip:7777;
  proxy_set_header Host             $host;
  proxy_set_header X-Real-IP        $remote_addr;
  proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
  proxy_set_header X-Accel-Internal /internal-nginx-static-location;
  access_log off;
  try_files $uri @missing;
  }
  
  location @missing {
   rewrite ^ /index.php last;
  }
  </code></pre>