title: Apache Conf - FilesMatch allow only in current folder, not subfolder
body: <p>is it possible to allow access to a specific file via &lt;files&gt; or &lt;filesmatch&gt; so that this rule is not applied to identically named files in subfolders?</p>
  
  <p>Current setup:</p>
  
  <pre><code>&lt;FilesMatch "\.php$"&gt;
      Deny from all
  &lt;/FilesMatch&gt;
  
  &lt;Directory /var/www/&gt;
      &lt;Files index.php&gt;
          Allow from all
      &lt;/Files&gt;
  &lt;/Direcotry&gt;
  
  &lt;Directory /var/www/admin/&gt;
      &lt;Files index.php&gt;
          Allow from all
      &lt;/Files&gt;
  &lt;/Direcotry&gt;
  </code></pre>
  
  <p>Let's assume the following:</p>
  
  <ol>
  <li>We have one index.php in web-root, one in subfolder admin, and in various other subfolders, there are also some index.php files.</li>
  <li>No *.php should be accessible, if not explicitely allowed - in this case only /index.php and /admin/index.php</li>
  </ol>
  
  <p><strong>What happens:</strong></p>
  
  <p>When allowing access to the webroots index.php, all index.php files in all subfolders become accessible.</p>
  
  <p><strong>What was tried:</strong></p>
  
  <p>Using DirectoryMatch to disallow access to index.php in subfolders.</p>
  
  <pre><code>&lt;FilesMatch ".+\.php$"&gt;
      Deny from all
  &lt;/FilesMatch&gt;
  
  &lt;Directory /var/www/&gt;
      &lt;Files index.php&gt;
          Allow from all
      &lt;/Files&gt;
  &lt;/Direcotry&gt;
  
  &lt;DirectoryMatch "/var/www/(.+)/"&gt;
      &lt;Files index.php&gt;
          Deny from all
      &lt;/Files&gt;
  &lt;/DirectoryMatch&gt;
  
  &lt;Directory /var/www/admin/&gt;
      &lt;Files index.php&gt;
          Allow from all
      &lt;/Files&gt;
  &lt;/Direcotry&gt;
  </code></pre>
  
  <p>Now, access to all index.php Files in all subfolders is disallowed - but also to the index.php in /admin/ which still should be allowed.</p>
  
  <p><strong>Also tried with absolut pathes to the files</strong></p>
  
  <pre><code>&lt;FilesMatch ".+\.php$"&gt;
      Deny from all
  &lt;/FilesMatch&gt;
  &lt;Files /var/www/index.php&gt;
      Allow from all
  &lt;/Files&gt;
  &lt;Files /var/www/admin/index.php&gt;
      Allow from all
  &lt;/Files&gt;
  </code></pre>
  
  <p>This also did not work.
  No index.php file was accessible - even the ones in the webroot and the admin-folder were not accessible.</p>
  
  <p>I believe that there are better approaches to solve a problem like this?</p>
  
  <p>Kind regards,</p>
  
  <p>Dominik</p>