How to prevent access to a directory with htaccess?
<p>How do I prevent access to a given directory ? Here is the structure of my website :</p>

<pre><code>config.php
.htaccess
classes/
|----lib/
|    |----...
|----classes.php
webroot/
|----index.php
|----ctrl/
|    |----...
|----pages/
|    |----...
|----style/
     |----...
</code></pre>

<p>The <code>DocumentRoot</code> is <code>webroot</code>. I want to prohibit access to the following folders : <code>ctrl</code>, <code>pages</code>, <code>style</code>. But the files stored in these folders still have to be available to be included in the <code>index.php</code> file.</p>

<p>In other words, there is an <code>index.php</code> file. Its role is to call (include) all the necessary files from <code>pages/</code>, ... The users can load <code>index.php</code> from their browser but they cannot access the other files alone.</p>

<p>I wrote this code is a <code>.htaccess</code> file but it doesn't do anything :</p>

<pre><code>deny from all
&lt;Files webroot/index.php&gt;
allow from all
&lt;/Files&gt;
</code></pre>

<p>This <code>.htaccess</code> file is located at the root folder for my project (before <code>webroot/</code>). What I try to do here is to deny access to every directory and files in the project except for the main <code>index.php</code> file.</p>

<p>What is it not working ? What went wrong ?</p>

<p>Thank you in advance.</p>