Forward Apache 500 status to 404

William W asked:

Short version: We’d like Apache to catch when a 500 status is given and return something like 404 instead. Is there a way to do this?

Longer version: These servers are running applications that aren’t ours, and they recently failed a PCI compliance scan because of the 500 status errors they can throw if you mess with the Host. In the long run we’ll move them to a different network so they don’t need to be PCI compliant, but in the short run we’d like a quick fix and just not show the 500 status that the applications return. Both applications this is happening with accept their requests through Apache.

I am hoping/assuming this would be a mod_rewrite rule, but don’t know to make mod_rewrite change based on status code.

My answer:


A PCI scan failure due to a 500 error? That’s a bit strange. Anyway…

Set up a default VirtualHost (you should already have one) that serves nothing; any requests made to it should then result in a 404.

<VirtualHost *:80>
ServerName *
DocumentRoot /var/empty
</VirtualHost>

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.