5

I am trying to deny everyone to download anything inside the "attachment" directory.

My website structure is:

    public_html
    -img
    -css
    -root
    --attachment
    ---(numeric id)
    ----(files)
    -js

What I am trying to do is, to deny access to root/attachment//

I tried many things, but I don't know why, I cannot get it working, my last tried was:

.htaccess - on main directory.

    <FilesMatch "root/attachment/.*/.*">
        Order Allow,Deny
        Deny from all 
    </FilesMatch>

Any ideas? Thank you very much :)

2 Answers 2

17

FilesMatch doesn't work with directories.

Create a new .htaccess inside root/attachment/ as

<FilesMatch ".*">
    Order Allow,Deny
    Deny from All
</FilesMatch>

Redirect rules specified in a parent directory .htaccess apply to its sub-directories as well. In case, these access rules do not work the same way, just move the .htaccess directly into files directory.

3
  • Ok, but the problem is that inside attachment I will have folders with each record id and inside each folder it will contain the files. Is it the only way? Should I create a .htaccess on each folder? Thanks :) Aug 13, 2013 at 9:57
  • 1
    @BrunoQuintanaFleitas Start with this file in the attachment directory. I'm hoping the access rules should trickle down to sub-directories. If that doesn't work then we would need to configure your httpd.conf file. Aug 13, 2013 at 10:30
  • this was the only option that worked for me. nobody says elsewhere that FilesMatch doesn't work with directories and DirectoryMatch doesn't work with files.
    – Ömer An
    Dec 26, 2018 at 20:19
0

Create a new htaccess file /root/attackment/.htaccess and add the following lines

Order Allow,Deny
Deny from all
1
  • 2
    will it allow my script to access that file... and also it will not be dowanloadable from the URL ...? Oct 21, 2014 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.