Webサイトをメンテナンスする際に、どのURLにアクセスしても「現在メインテナンス中です」というページを表示する方法。
ErrorDocument 503 /maintenance.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/maintenance.html
RewriteCond %{REMOTE_ADDR} !=xxx.xxx.xxx.xxx
RewriteRule ^.*$ - [R=503,L]
</IfModule>
<IfModule mod_headers.c>
Header set Retry-After "Sun, 15 Jun 2013 6:00:00 GMT"
</IfModule>
以下はメンテナンスページ(maintenance.html)の例。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Maintenance</title>
<style><!-- CSS の記述 -->
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,form,input,p,blockquote,th,td {
margin:0;
padding:0;
}
...(省略)...
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1 id="toptitle">My Site </h1>
</div><!-- end of #header -->
<div id="content">
<h2>ただいまメンテナンス中です。ご迷惑をおかけしております。</h2>
<p>Sorry. We're under maintenance.</p>
<p>メンテナンス期間:本日午前10時~11時</p>
<p id="contact"></p>
</div><!-- end of #content -->
<div id="footer">
<address>Copyright © My Site. All rights reserved. </address>
</div><!-- end of #footer -->
</div><!-- end of #container -->
<pre>
<script type="text/javascript"><!-- メールアドレスを表示する JavaScript の記述 -->
<!--
var contact = document.getElementById('contact');
contact.innerHTML = '<a h' + 'ref="ma' + 'ilt' + 'o:info' + "@" + 'mysite.com">info' + "@mys"+ 'ite.com</a>';
// -->
</script>
</pre>
</body>
</html>
メンテナンスを知らせるページを作っている時間がない(緊急にメンテナンスをおこなければならない)場合は、以下を .htaccess(またはhttpd.conf)の最後に追記すれば、ユーザーには「Sorry. We’re under maintenance.」というメッセージを表示し、検索エンジンには503を返すことができる。
ErrorDocument 503 "Sorry. We're under maintenance." RedirectMatch 503 .*