Apache オプション - サブディレクトリのインデックス

Apache オプション - サブディレクトリのインデックス

パーindex.html をアップロードしていない場合、親ディレクトリ内のファイルのリストを他のユーザーが閲覧できないようにするにはどうすればよいでしょうか?index.* ファイルがない場合にファイルのリスト表示を無効にする方法がわかります。

ルート ディレクトリのファイル一覧を許可し、他のサブ ディレクトリのファイル一覧を許可しないようにするにはどうすればよいですか?

前もって感謝します。

答え1

質問にタグを付けたので、 Apache 2.4 の.htaccessルート ファイルで次のような操作を行うことができます。.htaccess

# Default - Directory listings disabled (mod_autoindex)
Options -Indexes

# Override - Allow directory listings for the root only
<If "%{REQUEST_URI} == '/'">
    Options +Indexes
</If>

答え2

通常、サブディレクトリは、Apache の親ディレクトリに適用したのと同じ設定を継承します。また、私の知る限り、これを変更することはできず、ディレクティブのスコープを単一のディレクトリ レベルのみに制限する方法は存在しません。

つまり、次のことが必要です。

  • 親ディレクトリに必要なオプション/ディレクティブを設定します
  • すべての(現在のおよび新しい)サブディレクトリに対してそのオプション/ディレクティブを変更/上書き/否定します。

サブディレクトリごとに個別に行うよりも、DirectoryMatch指令。

メインのhttpd.conf(またはinclude)で設定します

<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>

(未検証)

関連情報