Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I disallow everything in a directory except any subdirectories that have a certain name using htaccess or even vhost.conf for the site? I have a protected main directory which contains subdirectories. Each of the subdirectories have another child dir named 'thumbs', that I want to allow people access to. In the thumbs folder I have files which all start with 'thumb_' prefix for the filename. So which approach to use, .htaccess FilesMatch or vhost DirectoryMatch? and what would be the code to use? Thanks

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

So if I'm understanding this right, you'll only want to allow files named thumb_* if they're inside a directory named thumbs, which is inside a subdirectory of the protected directory? It'd be simpler to not enforce the directory being named thumbs, since then you'd just need the <FilesMatch>.

Sounds like the path is, for example, /path/to/protected_dir/subdir/thumbs/thumb_1.png

If that's right, this should enforce the kinds of restrictions that you're looking for - just make sure there aren't other config blocks that might interfere with the permission settings:

<Directory /path/to/protected_dir>
  Order Deny,Allow
  Deny from all
</Directory>
<LocationMatch "^/url/path/to/protected_dir/[^/]+/thumbs/thumb_.*">
  Allow from all
</LocationMatch>

If you're not worried about enforcing the exact directory tree structure, this is a lot simpler:

<Directory /path/to/protected_dir>
  Order Deny,Allow
  Deny from all
  <FilesMatch "^thumbs_.*">
    Allow from all
  </FilesMatch>
</Directory>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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