Martin Vegter Martin Vegter - 15 days ago 10
Apache Configuration Question

How to match all files in a directory using Apache FilesMatch?

I need to restrict access to all files stored in

/sites/default/files/pdf/
on my Apache webserver. I have tried following
FilesMatch
expression, but that does not work.

<FilesMatch "sites/default/files/pdf">
AuthName "myauth"
AuthBasicProvider ldap
AuthType Basic
AuthLDAPURL ....
AuthLDAPBindDN ....
AuthLDAPBindPassword ...
Require valid-user
</FilesMatch>


Even matching for specific filename does not work (
<FilesMatch "sites/default/files/pdf/myfile\.pdf">
). Am I missing something?

Answer

try the Directory tag (or the Location tag if it is the URL and not the file path). You can check out the Apache docs, but Directory tag is for referencing the file system whereas Location is for the URL. There are differences, in cases where multiple URLS/symlinks can point to same directory, but syntax and basic function is the same. Don't forget the Allow/deny

    <Directory /sites/default/files/pdf>
     Order Deny, Allow
     Deny from all

     AuthName "myauth"
     AuthBasicProvider ldap
     AuthType Basic
     AuthLDAPURL ....
     AuthLDAPBindDN ....
     AuthLDAPBindPassword ...
     Require valid-user
    </Directory>

OR

    <Location /sites/default/files/pdf>
     Order Deny, Allow
     Deny from all

     AuthName "myauth"
     AuthBasicProvider ldap
     AuthType Basic
     AuthLDAPURL ....
     AuthLDAPBindDN ....
     AuthLDAPBindPassword ...
     Require valid-user
    </Location>