Require directive in .htaccess prevents directories from being shown

0

Issue

I have the following directory hierarchy

-root_folder
   .htaccess
   -sub_folder
       .htaccess

The content of the .htaccess file in sub_folder:

AuthType Basic
AuthName "webdav"
AuthUserFile /var/www/test/passwd.dav
Require user test

root_folder contains the following .htaccess

Satisfy any
Order deny,allow
Deny from all
Allow from env=ALLOWED
SetEnvIfNoCase Request_URI "^/+webdav/root_folder/?$" ALLOWED

Note, please, that i am using WebDav.

It is set up in /etc/apache2/conf.d/webdav. The file contains the following:

Alias /webdav /home/user/projects/test/public
<Location /webdav/>
    Order Allow,Deny
    Allow from #list of ips here
    DAV On
    PassengerEnabled off
    LimitXMLRequestBody 0
    Options Indexes FollowSymLinks
</Location>

The problem is that when i try to access localhost/webdav/root_folder/ folder using browser the sub_folder is not displayed.
But when i remove the Require user some_user directive the sub_folder is shown in the list. If i try to enter localhost/webdav/root_folder/sub_folder/ when Require user directive is enabled i’m asked to enter login and password and everything is ok if i enter correct credentials.

Is it possible to list everything within directory and at the same time use require user directives in .htaccess files inside sub_folders to control access to them?

Solution

In your root_folder (I believe that is your $DOCUMENT_ROOT) create .htaccess file with following content:

SetEnvIfNoCase Request_URI "^/*$" ALLOWED

Satisfy        any
Order          deny,allow
Deny from      all
Allow from     env=ALLOWED

If root_folder is not $DOCUMENT_ROOT then use:

SetEnvIfNoCase Request_URI "^/+root_folder/?$" ALLOWED

as the first line.

Answered By – anubhava

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More