.htaccess - mod_dir
mod_dir
以下は、mod_dir モジュールのディレクティブの一覧です。mod_dir は、ディレクトリへのリダイレクトと、ディレクトリのインデックスファイルを扱う機能を提供します。
DirectoryIndex ディレクティブ
DirectoryIndex ディレクティブは、クライアントがディレクトリ名の最後に /
を指定した場合に返すディレクトリインデックス(例えば、index.html、index.php など)を設定できます。複数のディレクトリインデックスを指定している場合は、最初に見つかったものを返します。それらが見つからず、Options ディレクティブ の Indexes が設定されている場合、ディレクトリのリストを返します。
# DirectoryIndex を設定する
DirectoryIndex index.html index.txt /cgi-bin/index.pl
上記の例では、index.html と index.txt のどちらもディレクトリ内に存在しない場合、CGI スクリプト /cgi-bin/index.pl が実行されます。ドキュメントが同じディレクトリ内に存在するは必要ありません。また、ディレクトリインデックスが見つからない場合は、以下のような画面が表示されます。

DirectorySlash ディレクティブ
DirectorySlash ディレクティブは、要求のあった URL がディレクトリを指すかを設定できます。例えば、ユーザが URL の末尾に /
無しでリソースにリクエストし、そのリソースがディレクトリを指していた場合、末尾に /
を付けてリダイレクトします。デフォルト値は On
になっており /
が自動的に付くようになっています。本ディレクティブの設定を Off
にした場合、DirectoryIndex ディレクティブが URL の末尾に /
が付いていないと評価しないため、ディレクトリのリストが表示され情報漏洩を招く可能性があります。
# DirectorySlash を設定する
DirectorySlash On
FallbackResource ディレクティブ
FallbackResource ディレクティブは、リクエストされたファイルが存在しない場合、指定されたパスにリダイレクトします。本ディレクティブは、Apache 2.2.16 以降で使用可能です。
# FallbackResource を設定する
FallbackResource /not-404.php
上記の例では、リクエストされたファイルが存在しない場合、not-404.php によって処理が行われます。本ディレクティブが使用できないバージョンでは、RewriteCond ディレクティブの -f
や -d
オプションを使ってファイルやディレクトリの存在確認を行います。本ディレクティブの機能を無効にするには disabled
を指定します。この設定値は Apache 2.2.24 以降で使用可能です。
関連記事
- .htaccess - コア機能
- .htaccess - mod_actions
- .htaccess - mod_alias
- .htaccess - mod_auth_basic
- .htaccess - mod_authn_default
- .htaccess - mod_authn_file
- .htaccess - mod_authz_default
- .htaccess - mod_authz_groupfile
- .htaccess - mod_authz_host
- .htaccess - mod_authz_user
- .htaccess - mod_autoindex
- .htaccess - mod_env
- .htaccess - mod_expires
- .htaccess - mod_filter
- .htaccess - mod_headers
- .htaccess - mod_imagemap
- .htaccess - mod_include
- .htaccess - mod_mime
- .htaccess - mod_negotiation
- .htaccess - mod_setenvif
- .htaccess - mod_rewrite