Use haproxy to redirect when 404 from the backend

haproxy

I'm using haproxy 1.5.18 and it does SSL termination and redirect to various backends using ACLs.

I would like to redirect the user (302) to a different page if the backend returns a 404. What's the best way to do this ?

I have found a thread dating 2009 and solves the problem using rsprep. Is it still the way to do it ?

Best Answer

frontend fe
  acl not_found status 404
  http-response set-header Location https://google.com/ if not_found
  http-response set-status 302 if not_found

It seems the http-response redirect syntax worked in haproxy 1.8, but in ubuntu builds we use it fails in 1.9 in a weird manner, and doesn't work at all in 2.0.