Forum Topic: Can’t get custom maintenance page to work

Forum: .htaccess Forum : Redirecting • Posted by Pete Clark • Updated:

Hello! I’ve been trying to set up the custom maintenance page as described in pages 98-99. The chunk of code on page 97 produces the expected result but when I add ErrorDocument 503 /maintenance.html I get the same ‘Service Temporarily Unavailable’ screen with the addition of this line:

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

I tried the ErrorDocument line before and after the rest of the code. Any help would be great thanks!

3 Replies to “Can’t get custom maintenance page to work”

Posted by Jeff Starr

Hi Pete! The error is caused by an infinite loop for the maintenance.html file.. there are two ways to fix:

  • add a rewrite condition for the maintenance file:
    RewriteCond %{REQUEST_URI} !/maintenance.html [NC]
  • add a rewrite condition for the 503 error:
    RewriteCond %{ENV:REDIRECT_STATUS} !=503

Either works fine, but it’s probably better to go with the latter, so it still works if ever the file name changes. Here is a working example:

# TEMP MAINTENANCE PAGE
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteCond %{REMOTE_ADDR} !^123\.456\.789
	# RewriteCond %{REMOTE_ADDR} !^111\.222\.333
	RewriteCond %{ENV:REDIRECT_STATUS} !=503
	RewriteRule .* - [R=503,L]
</IfModule>

ErrorDocument 503 /maintenance.html

<IfModule mod_headers.c>
	Header always set Retry-After "3600"
</IfModule>

This information will be added to the book for the next update. Thanks for bringing it to my attention!

Posted by Pete Clark •

Hi Jeff. What I didn’t mention is that I have css and images linked from the maintenance page, in a folder called ‘maintenance’. These extra files didn’t display using the second method. I found using the first method and adding the following did the job nicely though.

RewriteCond %{REQUEST_URI} !/maintenance/* [NC]

Thanks for your help!

Posted by Jeff Starr

Excellent point – thanks for the follow-up!