Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess, deny to download files within a directory

Tags:

.htaccess

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 :)

like image 558
peterpeterson Avatar asked Aug 06 '13 14:08

peterpeterson


People also ask

How do I deny access to my site with an .htaccess file?

htaccess IP deny access. To deny access to a block of IP addresses, simply omit the last octet from the IP address: deny from 123.456. 789.

What does htaccess Deny from all do?

htaccess to make it happen. For example, deny from all is a command that will allow you to apply access restrictions to your site.


1 Answers

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.

like image 127
Ravi K Thapliyal Avatar answered Sep 26 '22 17:09

Ravi K Thapliyal