.htaccessを使うと、httpd.confで設定するようなことを、httpd.confを書き換えなくても.htaccessというファイルを書き換えることによってユーザーが自分で設定することができる。
httpd.confを書き換えるには、通常root権限が必要ですが、この方法であれば、.htaccessを作成することさえできればよいという利点があります。その一方で、サーバの動作はhttpd.confを使うのに比べて遅くなるので注意すること。
なお、.htaccessを使うためには、httpd.confでAllowOverrideを許可する必要がある。
すべてを許可するには、
AllowOverride All
逆にすべて不許可にするには
AllowOverride None
一部機能だけを許可するには、Indexes、Options、FileInfo、AuthConfig、Limitがある。詳しくは書きのページを参照。
参考:http://httpd.apache.org/docs/2.2/ja/mod/core.html#options
ここでは、Basic認証を使用した、パスワード付きのページを作成する方法について記述する。
ExpiresActive On ExpiresByType image/gif A7200 ExpiresByType image/gif "access plus 2 hours" ExpiresByType image/jpeg M7200 ExpiresByType image/jpge "modification plus 2 hours" ExpiresByType text/html A600 ExpiresByType text/html "access plus 10 minutes" ExpiresDefault A86400 ExpiresDefault "access plus 1 day"
ErrorDocument 404 /404.html
httpd.conf内の下記の行を変更すれば、.htaccessの代わりにほかの名前を使うこともできる。
AccessFileName .htaccess
最終更新日