How to block access to files in the current directory with .htaccess

Posted by kfir on Server Fault See other posts from Server Fault or by kfir
Published on 2012-04-01T20:38:03Z Indexed on 2012/04/01 23:32 UTC
Read the original article Hit count: 208

Filed under:

I have a few private files in a public folder and I want to block access to them. For example lets say I have the following files tree:

  • DictA
    • FileA
  • FileA
  • FileB
  • FileC

I want to block access to FileB and FileA in the current directory and allow access to the FileA in the DictA directory. The first thing that came to mind was to use the FilesMatch directive as follows:

<FilesMatch "^(?:FileA)|(?:FileB)$">
  Deny from all
</FilesMatch>

The problem here is that FileA inside DictA will also be blocked, which is not what I wanted. I could override that by adding another .htaccess file to DictA but I would like to know if there is a solution which wont involve that.

P.S: I can't move the private files to a separate folder.

© Server Fault or respective owner

Related posts about apache2