PR

「ただいまメンテナンス中です」のための.htaccessファイル設定

サーバーメンテナンスのときに「只今メンテナンス中です」というメッセージを表示したい。その時に、あらゆるリクエスト(ブックマークされたなど)に対してもメッセージを表示したい。ただし、管理用エリアにはアクセスを許可したい。そんな場合の.htaccessはどう設定したらよいか。

スポンサードリンク

サンプル

もっと良い方法があるかもしれないけれど、とりあえず動作している。


<VirtualHost *:80>
# 2007-12-16 for Maintenance by CASEY
# 2008-01-17 for snort by CASEY
# 2008-09-06 bug fix by CASEY
# All Access go to index.html (Print Now Maintenance)
RewriteEngine on
RewriteRule ^/snort/(.*)$ - [L]
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule ^/.*$ /index.html [R]
</VirtualHost>


この例では次のように動作する

  • http://foo.jp
    -> http://foo.jp/index.html
  • http://foo.jp/index.html
    -> http://foo.jp/index.html
  • http://foo.jp/snort/
    -> http://foo.jp/snort/
  • http://foo.jp/sonzaisinai
    -> http://foo.jp/index.html

※メンテナンスメッセージファイルは /index.html にある

間違いや他の方法があったら教えてください。

(追記)その他の実現方法

方法1


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^pc.casey.jp(.*)
RewriteRule ^(.*)?$ http://www.casey.jp/errors/maintenance.html [R=302,L]
</IfModule>


方法2


Redirect temp / http://www.casey.jp/errors/maintenance.html


参考文献

oldId.20080905174331815