Apache Httpd Custom ErrorDocument 404 When ProxyPass returned 404

apache-2.2errordocumentmod-proxy

I have an Apache web server in front of another application server, using Proxy Pass. When the request to application returned error 404, I want to show custom error page from the web server not the one that come from application server. I have tried to setup the ErrorDocument 404 on the virtual host, but it doesn't work. How should I do this? Or this is not possible?

<VirtualHost *:80>
  ServerName servername
  DocumentRoot /somepath/
  ProxyPass / http://localhost:8080/someapp/
  ProxyPassReverse / http://localhost:8080/someapp/

  ErrorDocument 404 /error.html
</VirtualHost>

Best Answer

You can avoid proxying for a specific directory by specifying a ! in place of the proxy target. Since it acts on a directory, move error.html into a subdirectory (we'll say errors), and:

<VirtualHost *:80>
  ServerName servername
  DocumentRoot /somepath/
  ProxyPass /errors !
  ProxyPass / http://localhost:8080/someapp/
  ProxyPassReverse / http://localhost:8080/someapp/
  ProxyErrorOverride On
  ErrorDocument 404 /errors/error.html
</VirtualHost>