How can I return a 503 status in apache without invoking external scripts

I need to return a 503 status code from one of my sites while it's down for maintenance, in the time-honoured SE_firendly fashion. I can't seem to work out how to do this without invoking external scripts, which I'd rather avoid.

Is there an apache directive which will allow me to return an arbitrary HTTP status code without resorting to hacks like invoking a php script which sets the status header?

-
I'm not quite sure that running a PHP file classifies as a "hack"... that's sort of exactly what a web server is designed to do... –  Mark Henderson Aug 12 '09 at 3:55
Hm. I think invoking a whole interpreted scripting language to set a single line of the server response does qualify as hack. Setting lines of response headers without elaborate workarounds seems to me to be closer to what web servers were designed to do. –  dan mackinlay Aug 13 '09 at 16:35
Same question at webmasters.stackexchange.com/questions/61241/… –  rubo77 May 1 '14 at 8:12

This serves every request a static holding page along with the 503 status.

RedirectMatch 503 ^/(?!holding\.html)
ErrorDocument 503 /holding.html


RedirectMatch is used to negate the holding page itself which would otherwise create an infinite loop.

mod_header is used to set a Retry-After header so that you can tell Google/other bots etc that you should back up after 18000 seconds (5 hours) in this example. You can sudo ap2enmod header to activate mod_header (which is required for the Header directive).

-
Found this qn/answer a couple of years later doing the same search :) Took me a while to realize what was going on since I couldn't vote it up again! –  Tom Sep 24 '11 at 3:34
+1: A side comment: You can only add [RedirectMatch 503 .*] and the [Header always set Retry-After "18000"] rules and it works with the default 503 error message. Check for conf.d/localized-error-pages file to set a different message for different languages (those require negotiation, alias and include modules). –  lepe Apr 20 '12 at 1:08
It works! For my personal website, I use RedirectMatch 503 ^/(?!\.Error/.*|dragonlord-bg\.jpg). –  DragonLord Feb 9 '14 at 4:09

Try

Redirect 503

Other status codes can be returned by giving the numeric status code as the value of status. If the status is between 300 and 399, the URL argument must be present, otherwise it must be omitted. Note that the status must be known to the Apache code (see the function send_error_response in http_protocol.c).
-
Thanks david. mod_alias isn't where I expected to find that answer, but it seems to do the job. –  dan mackinlay Aug 13 '09 at 16:37
yeah, Redirect isn't really the right verb for what you're doing :) –  David Pashley Aug 13 '09 at 16:58
Redirect 503 it's missing one argoment, URL-path, which is always mandatory. URL on the other hand must be omitted if the redirected code is not 300-399 –  user33469 May 18 '10 at 15:32
I get an error doing that: "Redirect takes two or three arguments, an optional status, then document to be redirected and destination URL", can you give a more complete example in context? –  Tom Sep 24 '11 at 3:20
Redirect 503 / seems to work. –  mpartel Aug 24 '14 at 23:58