PDA

View Full Version : 404 question


JohnS
02-28-2009, 08:18 PM
Hello. I notice that, when I visit a nonexistent page on my site, it returns the following:

Not Found
The requested URL /example.php was not found on this server.

Additionally, a 301 Moved Permanently error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.41 Server at www.mysite.com Port 80

Should the 404.php document in my www directory be loading instead?

My htaccess file is:
RedirectMatch permanent ^(.*)\.htm(l?)$ $1.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]


Thanks in advance.

John

Jeff
02-28-2009, 08:41 PM
Possibly you need to explicitly set the ErrorDocument 404 to your 404.php file in the .htaccess file? (isn't the default looking for a .shtml or html 404 page?)

JohnS
02-28-2009, 08:51 PM
(isn't the default looking for a .shtml or html 404 page?)

I don't know. I'm very much a novice at site development and coding, but I will try to find out how to set the ErrorDocument as you said. Thanks for the suggestion.

By the way, the same error occurs even if I change the extension of the 404 file to html. (The file contains no php code, but I assumed that, since my htaccess redirects all html extensions to php, changing the extension on the 404 file to php was necessary.)

oheso
03-03-2009, 04:52 AM
I'm not an expert at regex, but at a cursory glance it looks like your htaccess code does not do what you expect it to do. Have you tested that thoroughly?

Meanwhile, the ErrorDocument code you're looking for is

ErrorDocument 404 /404.html

or

ErrorDocument 404 http://www.someserver.com/404.html

You can replace '404.html' with '404.php' if you prefer. (Actually, you can have both documents on your server and it won't hurt anything -- it just means you need to maintain two documents.)

Finally, there should be no trouble serving a strictly .html document as a .php.

JohnS
03-04-2009, 01:39 PM
Thank you, Jeff and Oheso. I added the errordocument code and it works great :-)