Apache でディレクトリ単位で404エラーページを変えるテスト。
実験環境:apache_1.3.33
の技術メモです。
httpd.conf に以下の部分を記載。
<Directory "/usr/local/apache_1.3.33/htdocs/test">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
ErrorDocument 404 /404.html
</Directory>
このディレクトリへのアクセスで 404 エラーのエラーページは、/404.html を表示させろという命令。
/404.html は予め適当に中身をつくっておいておく。
尚、DocumentRoot は /usr/local/apache_1.3.33/htdocs とする。
これで、
http://<サーバのIPアドレス>/hoge.html
http://<サーバのIPアドレス>/test/hoge.html
のように存在しないページを指定して反応の違いを確かめる。
---
リダイレクト先が存在しない場合は、通常の NotFoundページに加え、
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
というメッセージが出力される。ちなみに最初
/usr/local/apache_1.3.33/htdocs/404.html を作ったくせに
ErrorDocument 404 404.html
と書いてしまったため、上記のエラーが出てしまった。
ちなみに、httpd.conf で指定しないで、.htaccess に ErroDocument を書く場合には、
<Directory "/usr/local/apache_1.3.33/htdocs/test">
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>
とし、/usr/local/apache_1.3.33/htdocs/test/.htaccess に
ErrorDocument 404 /404.html
と書けば良いと思う。試したら出来ました。
グローバルに(表現は正しいかどうかわからんけど)
ErrorDocument 404 が書いてあってもこちらの内容がきちんと適用されました(両方試した)
apache2.0 では出来ませんでした!あはははー。なんでだー_| ̄|○
・・・と思ってやり直したらちゃんと動いたーorz
apache1.3.33、apache2.0.48 両方動作確認取れました。
