AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1078771
Accepted
morleyc
morleyc
Asked: 2021-09-28 05:11:03 +0800 CST2021-09-28 05:11:03 +0800 CST 2021-09-28 05:11:03 +0800 CST

Apache 选项 - 子目录的索引

  • 772

如果我没有上传index.html ,如何防止人们查看父目录中的文件列表?如果没有 index.* 文件,我可以看到如何禁用文件列表。

我如何允许根目录的文件列表,而不是任何其他子目录?

提前致谢。

.htaccess apache2
  • 2 2 个回答
  • 1723 Views

2 个回答

  • Voted
  1. new-user
    2021-09-28T05:40:18+08:002021-09-28T05:40:18+08:00

    通常,子目录将继承您在 Apache 中应用于其父目录的相同设置。而且,据我所知,您无法更改它,并且不存在将指令范围限制为仅单个目录级别的方法。

    这意味着您需要:

    • 在父目录上设置您想要的选项/指令
    • 更改/覆盖/否定所有(当前和新的)子目录的选项/指令。

    而不是单独为每个子目录执行此操作,而是使用DirectoryMatch指令执行此操作是最简单的。

    在您的主要 httpd.conf (或包含)集中

    <Directory "/path/to/example.com/">
      # enable directory listings
      Options +Indexes
    </Directory>
    
    
    <DirectoryMatch "/path/to/example.com/.*/">
      # Disable directory listings for all sub directories of /path/to/example.com/
      Options -Indexes
    </Directory>
    

    (未测试)

    • 3
  2. Best Answer
    MrWhite
    2021-09-28T07:14:14+08:002021-09-28T07:14:14+08:00

    由于您标记了 question .htaccess,您可以.htaccess在 Apache 2.4 的根文件中执行以下操作:

    # Default - Directory listings disabled (mod_autoindex)
    Options -Indexes
    
    # Override - Allow directory listings for the root only
    <If "%{REQUEST_URI} == '/'">
        Options +Indexes
    </If>
    
    • 2

相关问题

  • apache重写以将文件夹分配给域

  • Apache conf 或 .htaccess 规则将 404 重定向到特定文件类型的另一个位置

  • 如何让 Apache2 重定向到子目录

  • .htaccess - 删除所有 cookie

  • 我的 .htaccess 文件是什么意思?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve