Development System & Network

Serve static content, but with a 503 response code

We’re currently fronting our application cluster with a reverse proxy, and each upstream block has a fallback host that does nothing but serve a static maintenance page. So if all the backends fail it returns this page with a 200 OK, which is not the ideal return code for a number of reasons.

If my life was simple I’d just set ErrorDocument 503 /index.html and move on with my life, but the rub is that we serve this site in both english and french, and therefore have 2 different error pages. The mod_rewrite config is:

  RewriteCond %{REQUEST_URI} /EN [NC]
  RewriteRule ^/en$ /index-en.html [NC,L]

  RewriteCond %{REQUEST_URI} /FR [NC]
  RewriteRule ^/fr$ /index-fr.html [NC,L]

  RewriteCond %{HTTP:Accept-Language} ^fr [NC]
  RewriteRule .* /index-fr.html [NC,L]

  RewriteCond %{HTTP:Accept-Language} ^en [NC]
  RewriteRule .* /index-en.html [NC,L]

  RewriteRule (.*) /index-en.html [L]

My next shot was to add R=503 to the RewriteRules, but this causes Apache to return the default 503 ErrorDocument, and not our custom content.

Further complicating this is the fact that the “static” content in these pages is actually periodically regenerated from our CMS and cached so that it stays up to date, so I can’t simply drop in a quick-and-dirty PHP script to front this either.

Is there any way to accomplish this purely via Apache config?

Leave a Reply

Your email address will not be published. Required fields are marked *