Feb 9
I wanted to integrate my 404 page into my skins, but I needed it to be a .php file instead of .shtml (which is the default filetype I believe). So here’s how I did it.Open your existing .htaccess file. If you do not have one already, create a new file and save it as .htaccess. Add the following code to the file:
ErrorDocument 404 http://www.bubblessoc.net/404.php
You can change 404.php to anything you want. It can be error.php or mysiterox.php. And of course, you use your URL instead of mine
I’ve also integrated custom 404 pages for my subdomains as well using the same method. This is useful if you have hostees who want their own error pages. Just make an .htaccess file for each of your subdomains. Otherwise, the root .htaccess will take precedence.
If you want to display the name of the page that issued a 404 use:
<?php echo $_SERVER['REQUEST_URI'] ?>
Pretty nifty I think.
Meredith (Quote, )
Oh wait, LOL, I tried it and it’s not what I meant to look for. For some reason when users get a 404 on my site, instead of seeing the URL that wasn’t there still in the Location bar, they see the 404 page’s own URL. I haven’t figured out how to make the 404 not forward to the error page (losing the bad URL) or how to display the unfound page on the error page.
Fri Feb 10th, 2006 7:51 pm
Meredith (Quote, )
Oh wow, I was looking for exactly that (how do you print the page that caused the error) earlier today. Thanks!
Fri Feb 10th, 2006 7:46 pm
Dayna (Quote, )
I put a 404.php file in my themes folder for my error pages, so I don’t have to edit any
Mon Feb 13th, 2006 7:43 am
Bubs (Quote, )
That’s odd
I’ve never run across that problem.
Mon Feb 13th, 2006 5:50 pm
pbhj (Quote, )
Meredith, try not using the fully qualified URI – that causes apache to NOT send the error data as it thinks it’s going to an external URI.
eg
ErrorDocument 404 /mydocs/errrors/404.php
Mon Mar 6th, 2006 6:27 pm
The Mikeness (Quote, )
make sure your error handling page headers out the proper status code if necessary as well. I wrote a catchall page that I use for all ErrorDocument’s for all the status codes for which Apache will actually serve your custom page, it uses the $_SERVER['REDIRECT_STATUS'] variable that is set in PHP when the user is redirected to an error page.
You could possibly also do something like this:
httpd.conf:
ErrorDocument 403 /error/error.php?code=403
error.php:
(an array, $bob[403]= “403 Forbidden”)
header(‘Status: ‘.$bob[$_GET['code']]);
or substitute $_GET['code'] with the almighty $_SERVER['REDIRECT_STATUS'] (works with apache2 as a module, beyond that i cant guarantee anything)
I also have an array of messages for each error code, and its easy to build a MySQL logger to grab things that the likes of LogWatch cant, for example:
$_SERVER['HTTP_HOST']
$_SERVER['REDIRECT_STATUS']
$_SERVER['REDIRECT_REQUEST_METHOD']
$_SERVER['SERVER_PORT']
$_SERVER['REQUEST_URI']
$_SERVER['REDIRECT_URL']
$_SERVER['REMOTE_ADDR']
$_SERVER['HTTP_USER_AGENT']
$_SERVER['HTTP_COOKIE']
$_SERVER['HTTP_ACCEPT']
$_SERVER['HTTP_ACCEPT_ENCODING']
$_SERVER['REQUEST_METHOD']
$_SERVER['QUERY_STRING']
Fri Oct 31st, 2008 10:15 am