apache.htaccessmod-rewriteerrordocument

Redirect all but one page to error 503 custom page


htaccess for apache server cause all my IIS servers will be down on maintenance. I need to redirect everything to error 503 custom page and also return the 503 error, but I don't know the correct sollution.

RewriteEngine on
RewriteBase /

ErrorDocument 503 /503.html

RewriteRule ^.*$ - [L,NC,R=503]

This result into this: (the response is not my custom response)

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

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

Another try:

RewriteEngine on
RewriteBase /

ErrorDocument 503 /503.html

RewriteRule ^(?!503.html)$ - [L,NC,R=503]

Gives me what I need but just for www.domain.com and every other page gives me 404 (except www.domain.com/503.html which gives me 200).

So what I need is to redirect every page but the domain.com/503.html to custom 503 error page and also return the error code.


Solution

  • You can use negation:

    RewriteEngine on
    
    ErrorDocument 503 /503.html
    
    RewriteRule !^503\.html$ - [L,NC,R=503]