Custom 404 page issues


#1

I’m having a weird issue with my custom 404 error page. Clicking on a link or typing http://mydomain.com/not-here.php
doesn’t call the custom 404 error page. But oddly, this: http://mydomain.com/not-here.htm will pull up the custom 404 error page. To confuse things further, this: http://mydomain.com/not-here/not-here.php works. (as does .htm.)

My .htaccess file contains:
ErrorDocument 404 /missing.php

So what happens is when an htm file is not found, the 404 page is displayed. When a php file is not found, I get the message “No input file specified.” Any file not found in a sub-directory works. I know that the files don’t exist, because I’m entering random letters (asdfasdf.php wwlfkfa.htm).

I did some searching on the K-base and on this forum and the answer seems to be an .htaccess file with the contents that I have.

I have the same setup on another domain, and it works as expected. The one I’m having problems with is a new domain.

Any ideas?

TIA
John


#2

What does it say in your error logs, if anything?

:cool: Perl / MySQL / HTML+CSS


#3

In the failure report part of the site statistics, none of the root level files are listed. There are only 8 failures listed, but should be lots more than that.


#4

Well I meant your Apache error.log file in /home/username/logs/domain/http/error.log

:cool: Perl / MySQL / HTML+CSS


#5

Sorry.
Here is the log from friday:

[Fri Oct 1 07:26:07 2004] [error] [client IP] File does not exist: /home/user/domain.com/nothere.htm
[Fri Oct 1 07:26:41 2004] [error] [client IP] File does not exist: /home/user/domain.com/nothere.htm
[Fri Oct 1 07:27:31 2004] [error] [client IP] File does not exist: /home/user/domain.com/nopgwe.htm
[Fri Oct 1 07:39:43 2004] [error] [client IP] File does not exist: /home/user/domain.com/erfd.htm
[Fri Oct 1 07:42:14 2004] [error] [client IP] File does not exist: /home/user/domain.com/asdfe.htm
[Fri Oct 1 07:43:29 2004] [error] [client IP] File does not exist: /home/user/domain.com/ssdfd.htm
[Fri Oct 1 07:46:03 2004] [error] [client IP] File does not exist: /home/user/domain.com/asdf.htm
[Fri Oct 1 07:51:08 2004] [error] [client IP] File does not exist: /home/user/domain.com/fdsas.htm
[Fri Oct 1 07:51:16 2004] [error] [client IP] File does not exist: /home/user/domain.com/dsf.htm
[Fri Oct 1 07:51:17 2004] [error] [client IP] File does not exist: /home/user/domain.com/john.htm
[Fri Oct 1 07:51:35 2004] [error] [client IP] File does not exist: /home/user/domain.com/index
[Fri Oct 1 07:51:57 2004] [error] [client IP] File does not exist: /home/user/domain.com/press.htm
[Fri Oct 1 07:52:23 2004] [error] [client IP] File does not exist: /home/user/domain.com/press.htm
[Fri Oct 1 07:53:57 2004] [error] [client IP] File does not exist: /home/user/domain.com/about_us.htm
[Fri Oct 1 13:05:34 2004] [error] [client IP] File does not exist: /home/user/domain.com/press.htm
[Fri Oct 1 16:01:05 2004] [error] [client IP] File does not exist: /home/user/domain.com/press.htm
[Fri Oct 1 16:01:43 2004] [error] [client IP] File does not exist: /home/user/domain.com/press/index.php
[Fri Oct 1 16:01:54 2004] [error] [client IP] File does not exist: /home/user/domain.com/press/index.htm
[Fri Oct 1 16:05:15 2004] [error] [client IP] File does not exist: /home/user/domain.com/press/
[Fri Oct 1 16:05:34 2004] [error] [client IP] File does not exist: /home/user/domain.com/press/
[Fri Oct 1 16:05:46 2004] [error] [client IP] File does not exist: /home/user/domain.com/press/press.php

There are no .htm files in the site.
The press directory does not exist.
The press.php file does not exist, but does not trigger the 404 page and does not show in the logs.
(the only .php file that show up in the logs are the ones in subdirectories.)

Thanks
John


#6

That’s a known issue when running PHP as CGI… though I’m not sure why there would be a difference between subdirectories?


Pointy-Ears.net


#7

No, this is another site I’m working on.
This link should get you to the working 404 page:
http://dev.puppetryforum.com/john/john.php
(this is a development version of the www site.)

The 404 page works there–on root level and below.

So, if this other site is older, it maybe is not run as CGI?

I’ll contact support.

Thanks.
JOhn


#8

I’m having the exact same problems as John described… does anyone have any ideas?

Thanks in advance for any help…
–Alex


#9

If you read the thread, the upshot is that PHP-CGI is a wrapper program that has to find the PHP file to execute - and if there is no such file, it does not pass status 404 back to Apache.

A work around is to use mod_rewrite with a condition that if the SCRIPT_NAME file does not exist, the URL is re-written to a “missing.php” file that does exist, something like:

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{SCRIPT_NAME} !-f RewriteRule (.+) /missing.php?request=$1 [PT] </IfModule> #EndWhich is an example based on the one Wes posted in the KBase article.

:cool: Perl / MySQL / HTML+CSS


#10

These .htaccess scripts do not seem to be redirecting anything on my site. The one listed in the post I am replying to returns a 500 internal server error (you can check it out for yourselves at http://www.digitalovertone.com/badurl.php). All the scripts listed in the kbase article on how to hack PHP-CGI to show custom 404s return similar errors. This is beginning to get very very frustrating. The .htaccess file I am currently working with is:

RewriteEngine On
RewriteCond %{SCRIPT_NAME} !-f
RewriteRule (. ) /404.php [PT]

The file 404.php is at http://digitalovertone.com/404.php.

Please help!

Edit: The above script in fact resulted in a 500 internal server error on EVERY page. It is now gone. The problem, however, remains.


#11

OK, tested this, works for me (PHP-CGI):

RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule (. ) /path/missing.phpFirst condition tests pathname to make sure it is not a file.
Second condition tests pathname to make sure it is not a directory.

This works because before the PHP script is run, SCRIPT_FILENAME is the pathname to the script file, eg /home/username/example.com/nothing.php

While the PHP script is running SCRIPT_FILENAME will be /dh/cgi-system/php.cgi though, so don’t get confused.

:cool: Perl / MySQL / HTML CSS


#12

So this works for badurl.htm(l), but not badurl.php. Is there any way to get the custom 404 for the latter? Should I just switch to running PHP as an Apache module? Is that as terrible an idea as the kbase makes it seem?


#13

What? Who said that?

It works for all requests, because the conditions check if the url-path is to that of a file or a directory. If there is no such file or directory, then the rule causes the missing.php file to run

This is the output I get, where missing.php is the only file that exists:[code]http://atropos.openvein.org/web/dreamhost/apache/php/bad.php
HTTP 404 Not found
SCRIPT_NAME: /cgi-system/php.cgi
SCRIPT_FILENAME: /dh/cgi-system/php.cgi
REQUEST_URI: /web/dreamhost/apache/php/bad.php
DOCUMENT_URI:
SCRIPT_URI: http://atropos.openvein.org/web/dreamhost/apache/php/bad.php

http://atropos.openvein.org/web/dreamhost/apache/php/bad.html
HTTP 404 Not found
SCRIPT_NAME: /cgi-system/php.cgi
SCRIPT_FILENAME: /dh/cgi-system/php.cgi
REQUEST_URI: /web/dreamhost/apache/php/bad.html
DOCUMENT_URI:
SCRIPT_URI: http://atropos.openvein.org/web/dreamhost/apache/php/bad.html

http://atropos.openvein.org/web/dreamhost/apache/php/missing.php
HTTP 404 Not found
SCRIPT_NAME: /cgi-system/php.cgi
SCRIPT_FILENAME: /dh/cgi-system/php.cgi
REQUEST_URI: /web/dreamhost/apache/php/missing.php
DOCUMENT_URI:
SCRIPT_URI: http://atropos.openvein.org/web/dreamhost/apache/php/missing.php[/code]As you can see, the SCRIPT_NAME and SCRIPT_FILENAME variables will report the wrapper executing PHP-CGI, instead of the script missing.php

:cool: Perl / MySQL / HTML+CSS


#14

I’m sorry, I wasn’t intending to put words in your mouth! I was reporting my own experience. Utilizing your script on my site, “badurl.php” returns the all-too-familiar “no input file specified,” whereas “badurl.htm” directs me to my 404. I don’t know where to find the output you reported, so I can’t tell you what I’m getting.

I ran a few tests, and here are my results:

  1. Read directories, fake files
    digitalovertone.com/badurl.html -> redirected to 404.php
    digitalovertone.com/badurl.php -> no input file specified
    digitalovertone.com/logue/index2.php -> no input file specified

  2. Fake directories, fake files
    digitalovertone.com/baddir/ -> redirected to 404.php
    digitalovertone.com/baddir/badurl.php -> redirected to 404.php

So it seems like I am still having problems redirecting *.php files in real, existing directories. Any thoughts?


#15

That is interesting. Today I was using a script called test.php that I kept modifying, then switching to my browser and refresh. Well anyway, at one point I moved the file to another directory, but forgot to change the URL in my browser and was getting the “No input file specified” that you mention. I spent probably a good 2 or 3 minutes checking my script because the script involved reading external files and I thought I messed something up!

I have not messed with any custom 404 pages, so really I am just confirming for you that typing in a non existant .php file in a real directory gets me the same “No input file specified” instead of a 404. Which to me seems like a bug …


#16

It’s a known bug. When the server sees a request for a PHP file because of the extension, it runs a wrapper which has to then load the PHP script file mentioned in the request. If it turns out the script file does not exist, the server is not able to process that, and you get the message from PHP instead saying it has no script to run.

The code I posted works for me. There is a difference if it is running PHP 4 or 5. With PHP 4, the SCRIPT_NAME and SCRIPT_FILENAME were set to the wrapper. In PHP 5, it is set the PHP script instead. I am not using ErrorDocument 404 because the Rewrite rule makes it unnecessary.
The URI to my missing.php file is
http://atropos.openvein.org/web/dreamhost/apache/php/missing.php

:cool: Perl / MySQL / HTML+CSS