3

We are using an Apache httpd as reverse proxy. In special cases when an error occurs in the backend system, it returns a special header like X-Error=1 (besides the status code 500).

Is it somehow possible to redirect those repsonses based on the presence of named response header? Redirect to a static error page for example. Unfortunately it is not possible to return a status code different from 500, which would solve described problem.

ahaertig
  • 65
  • 1
  • 7
  • The [values of other headers can be obtained with the `req` function](http://httpd.apache.org/docs/2.4/expr.html#vars), of which [`resp` might help you](http://httpd.apache.org/docs/2.4/expr.html#functions). – Colt Jul 01 '16 at 10:41

1 Answers1

0

Apologies as this answer is somewhat speculative. I think this will be quite difficult to achieve, but here are some possible solutions.

  1. You could write your own HTTP handler in mod_lua or similar.
  2. You could write an external filter, using mod_external_filter to find the header and then change the response appropriately. This is essentially a "poor mans" version of writing your own handler.
  3. You might be able use ProxyErrorOverride to change the page Apache displays when its gets a 500 response from the backend. If you set it to a CGI local to Apache, you could test for the presence of the header and display the response you wish, otherwise display a default response.

In theory, these all do the same thing. Capture the response before it is sent back to the client and then modify it as necessary.

Unbeliever
  • 2,336
  • 1
  • 10
  • 19