How to block directory files recursively?

Asked

Viewed 280 times

2

I am trying to block all files from a particular directory except for .js , .jpg , .css , .gif , .png.

I have this code, but it’s not working the way I want it to:

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

Someone could tell me where I’m going wrong ?

  • You’re wearing .htaccess in your project?

2 answers

1


Configure on your Virtualhost the following Directives:

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

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

The first directive will block all extensions, the second will allow informed extensions.

This will be applied recursively from the directory in Documentroot of your Virtualhost.

  • that I put in . htaccess correct ?

  • my server he Cpanel do not know how to configure without htaccess

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>
  • I believe the question is how to block recursivamente, avoiding having to put a file .htaccess in each folder...

  • If you put it in the root, it will take all the directories below and so on. If you put it in a folder called Assets for example, it will affect all subdirectories of Assets.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.