How to block directory files recursively?

2

I'm trying to block all files in a particular directory with the exception of .js , .jpg , .css , .gif , .png .

I have this code, but it is not working the way I want it to be:

<Files ~ "\.(jpg|jpeg|png|gif|css|js)$">
   order deny,allow
   allow from all
</Files>

Could someone guide me where I'm wrong?

    
asked by anonymous 26.05.2017 / 21:41

2 answers

1

Configure the following directives in your VirtualHost :

<Files ~ "\.*$">
        Deny from all
</Files>

<FilesMatch ".*\.(jpg|jpeg|png|gif|css|js)$">
        Order Allow,Deny
        Allow from all
</FilesMatch>

The first policy will block all extensions, the second will allow the extensions to be informed.

This will be applied recursively from the directory entered in the DocumentRoot of your VirtualHost.

    
29.05.2017 / 19:37
0

Hello, add in the folder you want to lock the files the following code below in .htaccess. Note: This lock is recursive.

Order deny,allow
deny from all

# Allow access to html files
<Files ~ "^.*\.(jpg|jpeg|png|gif|css|js)$">
    allow from all
</Files>
    
29.05.2017 / 19:25