I'd like to limit access to some specific PDF files but am having a bit of trouble with my Apache configuration. I've got the FilesMatch directive to work as follows:
<FilesMatch "\.pdf$">
AuthName "Permission Required"
AuthUserFile /path/to/.htpasswd"
Require valid-user
AuthType Basic
</FilesMatch>
Now I understand that I can't be more specific in just my .htaccess file, and so I'd have to use LocationMatch or DirectoryMatch in my config file. I've tried the following, but with no success:
<VirtualHost *:80>
DocumentRoot "/var/www/somedomain.com/httpdocs"
ServerName somedomain.com:80
ServerAlias somedomain.com
<DirectoryMatch "^/uploads/(dir1|dir2)">
<FilesMatch "\.pdf$">
AuthName "Permission Required"
AuthUserFile "/var/www/somedomain.com/bin/.htpasswd"
Require valid-user
AuthType Basic
</FilesMatch>
</DirectoryMatch>
</VirtualHost>
The actual files are located: http://www.somedomain.com/uploads/dir1/somefile.pdf
I'm sure it's something simple, but I just can't get it to work correctly.
FilesMatchand didn't close it (this applies toDirectoryMatch).