apache - .htaccess 中的 Require 指令阻止显示目录

标签 apache .htaccess apache2 webserver authorization

我有以下目录层次结构

-root_folder
   .htaccess
   -sub_folder
       .htaccess

sub_folder中.htaccess文件的内容:
AuthType Basic
AuthName "webdav"
AuthUserFile /var/www/test/passwd.dav
Require user test
root_folder包含以下内容 .htaccess
Satisfy any
Order deny,allow
Deny from all
Allow from env=ALLOWED
SetEnvIfNoCase Request_URI "^/+webdav/root_folder/?$" ALLOWED

请注意,我正在使用 WebDav .

设置在/etc/apache2/conf.d/webdav .该文件包含以下内容:
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>

问题是当我尝试访问 localhost/webdav/root_folder/ 时文件夹使用浏览器sub_folder不显示。
但是当我删除 Require user some_user 时指令 sub_folder显示在列表中。如果我尝试输入 localhost/webdav/root_folder/sub_folder/Require user指令已启用,我被要求输入登录名和密码,如果我输入正确的凭据,则一切正常。

是否可以列出目录中的所有内容并同时使用 require user sub_folders 内的 .htaccess 文件中的指令来控制对它们的访问?

最佳答案

在您的 root_folder (我相信那是您的 $DOCUMENT_ROOT )中创建具有以下内容的 .htaccess 文件:

SetEnvIfNoCase Request_URI "^/*$" ALLOWED

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

root_folder不是 $DOCUMENT_ROOT 然后使用:
SetEnvIfNoCase Request_URI "^/+root_folder/?$" ALLOWED

作为第一行。

关于apache - .htaccess 中的 Require 指令阻止显示目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706911/

相关文章:

linux - Apache 2.4.18,403 : Forbidden

apache - www 到非 www 重定向不起作用

php - PHP 中的依赖注入(inject)

php - .htaccess 用于使用 Yii 框架的子目录中的站点

apache - 如何验证 Apache 缓存是否正常工作?

html - 文件夹中的 Apache htaccess : Block direct access to index. html

php - htaccess RewriteRule 读取文档根目录之外的图像

apache - mod_rewrite 规则在 apache 重启后失败

phpmyadmin - 拒绝特定用户的登录

Apache + WSGI : Address already in use: make_sock: could not bind to address