Block direct access to files and directories

5

Well, my question is simple:

How can I block direct access to files and directories on my site? For example, prevent the user from accessing the link: www.meusite.com/img and get the list of images, or /js and get the JS files, and so on.

Today I have a blank file index in each folder, which "blocks" the access, or rather the view.

I tried to use htaccess to create this lock, something like this:

<Directory  ~ "\">
    Order allow,deny
    Deny from all
</Directory>

But I'm getting total blocking, not even site navigation is allowed. The only other setting I have in my htaccess is rewrite to improve url of the site. Since I am working with routes in AngularJs , the code below is to remove the /#/ that is added.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
</IfModule>

How can I get the result? I have already visualized some sites that when accessing the folder, we obtain the result of "Forbiden access" which, I believe, is the most correct process to be done.

Or ... What is the real purpose / logic that I should have in this regard?

    
asked by anonymous 26.07.2016 / 15:50

1 answer

7

The option you are looking for is this:

Options -Indexes 

You can direct it to .htaccess (if this override is enabled in Apache).

Configuration example with Directory , instead of .htaccess :

<Directory /caminho> 
    Options -Indexes 
</Directory>

Documentation (en):

  

link

    
26.07.2016 / 15:54