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

I have such directiry structure:

- www
    - folder1
        - folder2
            - folder21
            - folder22
            - folder23

I allowed all image files to be accessed

<FilesMatch \.(?i:gif|jpe?g|png)$>
    Order Deny,Allow
    Allow from all 
</FilesMatch>

I allowed all all files in certain folder to be accessed

<FilesMatch /folder2/folder22/.*>
    Order Deny,Allow
    Allow from all 
</FilesMatch>

I allowed all robots.txt files to be accessed

<FilesMatch (robots\.txt)$>
    Order Deny,Allow
    Allow from all 
</FilesMatch>

And at the end I added password restriction

AuthType Basic
AuthName "Personal use"
AuthUserFile /full/path/to/.htpasswd
Require valid-user

But when I try to access any image file via browser, I get password prompt. Could anyone explain how to fix it and what might be the problem. Thank you.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Order Deny,Allow means that the deny rules are processed before the allow rules. Therefore, you will get a password prompt.

For any folders and filetypes that you want to allow access, just put the below config into your .htaccess:

<FilesMatch "\.(gif|jpe?g|png)$">
    Order Allow,Deny
    Allow from all 
    Satisfy Any
</FilesMatch>
share|improve this answer
    
It helped only for images rule. Tryed this rule /folder2/folder22/.* and it prompted me for password too. –  Eugene Aug 8 '11 at 9:50
    
Use <Directory> directive for the folders. –  quanta Aug 8 '11 at 9:57
    
It use isn't allowed in htaccess and I can configure only from there. –  Eugene Aug 8 '11 at 9:59
    
echo "Satisfy any" > /path/to/folder2/folder22/.htaccess and try again. –  quanta Aug 8 '11 at 10:14
    
So it should be outside FilesMatch bloks? Also I need .htaccess file to be in upper level directory, not inside /path/to/folder2/folder22/. –  Eugene Aug 8 '11 at 10:32

You just need to add a satisfy Any directive to each of the FilesMatch blocks.

<FilesMatch \.(?i:gif|jpe?g|png)$>
    Order Deny,Allow
    Allow from all
    Satisfy Any    
</FilesMatch>
share|improve this answer

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.