title: Cascade index.php in nginx "try_files"
body: <p>In Apache it is possible to redirect everything to the closest index.php, using <code>.htaccess</code></p>
  
  <p>Example folder structure:</p>
  
  <pre><code>/Subdir
  /index.php
  /.htaccess   
  
  /Subdir
  /Subdir/.htaccess
  /Subdir/index.php
  </code></pre>
  
  <p>If I access <code>/something</code> it will redirect to the root index.php, and if I access <code>/Subdir/something</code> it will redirect to <code>Subdir/index.php</code></p>
  
  <p>Can this be done in nginx as well?
  It should be possible, because in nginx documentation it says <code>If you need .htaccess, you’re probably doing it wrong</code> :)</p>
  
  <p>I know how to redirect everything to the root index.php:</p>
  
  <pre><code>location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
  </code></pre>
  
  <p>But how to check for index.php in every parent directory until <code>/</code> ?</p>
  
  <p>edit:</p>
  
  <p>I found that these rules do what I want:</p>
  
  <pre><code>location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
  
  location /Subdir{
    try_files $uri $uri/ /Subdir/index.php?$query_string;
  }
  </code></pre>
  
  <p>But is there a way to make it abstract, like</p>
  
  <pre><code>location /$anyfolder{
    try_files $uri $uri/ /$anyfolder/index.php?$query_string;
  } 
  </code></pre>
  
  <p>?</p>