No input file specified – php custom 404 errors

Question:

I am trying to create a custom 404 using php. However I just get the error “No input file specified”

Any ideas?

Answer:

This occurs when you are running php as a cgi and an non-existant php page is called. When php runs as a cgi the webserver never checks for valid files – it just sends the request straight to the php parser. The php parser does not return a 404, instead it errors with “No input file specified”

Add the following to your .htaccess (or create a .htaccess file if you don’t already have one) and it should fix it

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /file_that_does_not_exist

The code above will cause the server to check for valid files first and redirect to a file that does not exist and trigger the 404.

Leave a Reply

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