Dreamhost prefers users to run PHP as CGI program rather than as an Apache module, for security reasons. I’m totally fine with this, but it has some drawbacks. The only one I’ve actually noticed is that it utterly breaks custom 404 pages. I think this is fixed in PHP 5, but it’s still in whatever version this server is running.
The server doesn’t spring a 404 error because it’s just passing the requested filename as a parameter to php.cgi, wherever it may reside. When it can’t find the file, it responds with its own error message:
No input file specified
If you’ve gone to the trouble to set up custom pages in your site style, it’s more than a little annoying to have them replaced by something so utterly useless, unhelpful, and downright confusing.
But now, I notice, someone’s posted a solution! It’s a clever bit of mod_rewrite hackery.
RewriteEngine on
Rewritecond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.php$ /404.html
!-f checks to see if the requested .php location exists and is a real file. If not the rewrite rule will direct to the chosen error document. The only real drawback I can see is that it’ll mess with requests for things other than real files — notably, symlinks.
It’s also not perfect if you have a single error.php file, and use $_SERVER['REDIRECT_STATUS'] to display different messages for different error types, since the server still doesn’t think there’s an error. Instead, you have to do something like this:
RewriteRule \.php$ /error.php?error=404
And then check $_GET['error'] in the script. But it’s still much, much better than nothing.
THat’s a stupid solution and a complete waste of server resources - you’re a stupid fuck!
Thanks for your input. Please feel free not to contribute again.
lol!
Hey, thanks. I was looking for something to fix my Dreamhost custom 404 problem when using php pages, and this did it.
No more useless “file not found”
I launched this blog in January 2003 and since then have posted over 1100 entries. It’s been a learning experience. I’ve changed the blog’s file structure a few times. If you blog and you use a blogging content management system…
Thanks for this. I’ve been trying to figure out what was going on…
Thanks for the tweak. I have my (dreamhost’d) PHP error pages working. Note, since they moved to the WIKI, you link is DOA
“Jason Myer” (first entry)…a bit too angry. Clearly he needs a hug (and a dictionary since he’s a bit of a “language Philistine”). Poor, sad, Jason.
It works for normal pages as well as missing pages… but if I try to GET a directory with an existing index.html, it returns the 404 page instead of the index.html
Aaron: not without more details. There are some Apache directives that just won’t work properly (like AddHandler) — you have to redirect instead.
Here is How to Resolve this message when the php file does not exist!
If you are running IIS and want to have a custom 404 error page displayed instead of the “no input file specified”.
IIS Custom “No input File Specified” error (seo)
This only works for IIS and you have to have access to IIS.
Open IIS, Expand Web Sites folder and right click your website, choosing properties.
Then select tab labled “Home Directory”. Can be recognized if inner box has statement local path: [C:/urweb] [Browse]
Under that section you should see Application Settings,
application Name:
Starting Point:
Execute Permissions:
to the right of those statements is a button labeled [Configuration…] select that button.
New window reads at top
“Application Configuration”
then has a list of extensions and their executable Paths.
Scroll down to .php and select button [edit]. New window reads “Add/Edit Application Extension Mapping” Look towards the lower part of that window for the check box “Verify that file exists”. This should be checked if you want IIS to verify the php file exists first. If the file does not exist then IIS will provide whatever 404 error message you have set in IIS if any Else it will provide it’s own generic default IIS 404 error.
If you need more help finding that specific window the do a search for IIS “Verify that file exists” or “add edit application extension mapping”
cheers.