Making Apache return the same page for all URLs

I am currently developing and maintaining a web application running on Apache. In this context I have sometimes needed to take the site down in order to roll out new versions of the underlying software. Instead of taking down the web server entirely and having the users get error messages from their browsers, I naturally want to present a “Down for maintenance” page.

Doing this for the root URL of the application was a simple matter of making a new configuration file, with the same ServerName parameter, in the sites-available directory. This new configuration file points at a DocumentRoot containing a single index.html containing the wanted message.

However, trouble struck when trying to access anything but the root URL. I tried redirecting all requests to the root URL with AliasMatch and RedirectMatch but kept making redirect loops. My attempts at googling for a solution kept pointing me at these two directives and mod_rewrite, from which I expected the same trouble.

After browsing the Apache documentation I stumbled upon the ErrorDocument directive, which allows specifying what should be returned in case of errors. Adding this line to my “site down” configuration made everything work:

ErrorDocument 404 /

Because the site only contains the single index.html accessing anything else will result in 404 error, which the ErrorDocument directive specifies should result in the root of the site being returned.

This is probably well known stuff for most Apache administrators, but given the trouble I had finding it, I thought it might help other newcomers to post about it.