モンスターカレンダー

« 2010年8月 
12345678910111213141516171819202122232425262728293031

メンテナンス中画面を出す正しい作法:503を返す

サイトメンテナンス中は、メンテ中画面を単に表示しているだけだったが、ステータス503を返しておくのがよいとのこと。

メンテナンス中画面を出す正しい作法と.htaccessの書き方

.htaccessに以下のように書けばOK。

ErrorDocument 503 /maintenance.html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/maintenance.html
RewriteRule ^.*$ - [R=503,L]
</IfModule>

これは簡単。と適用してみると500エラーになってしまう。
エラーログには「RewriteRule: invalid HTTP response code for flag 'R'」と出ている。
調べてみると「RewriteRuleでR=503を指定するのは2.2系でしか使えない」だそうだ。上述のページのコメント欄に指摘があり、今回対象のサーバは使えないようだ...

メンテナンス画面を表示させる方法(Apache 1.3対応版)

上記の設定でようやくOK。

●503を返す503.phpを作成。
<?php
header ('HTTP/1.0 503 Service Temporarily Unavailable');
include(dirname(__FILE__) . '/index.html');
?>
●.htaccessの設定。

RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.swf$
RewriteCond %{REMOTE_ADDR} !=192.168.0.1 #(管理者のIPアドレス)
RewriteCond %{REQUEST_FILENAME} !503.php
RewriteRule ^.*$ /maintenance/503.php [R,L]

ほんの10分で済む予定が1時間かかってしまいました。。