views:

111

answers:

2

Although I'm sure it's possible I cannot see how I would be able to do the following.

Using .htaccess to point the html errors to a single error handling page (this bit not a a problem).

That page then checks what the error code actually was (404, 500 etc.) and displays a message according to each one.

I am trying to do it in a PHP environment, and it's for a minimalistic site so the less files the better.

This is an example of a 404 I'm producing, http://isitup.org/404, and all I want is to switch the number accordingly.

+6  A: 

I always put in my .htaccess:

ErrorDocument 403  /error.php?error=403
ErrorDocument 404  /error.php?error=404
ErrorDocument 500  /error.php?error=500

etc for whatever errors I want, then just switch case on $_GET['error'].

Don't think there is any more sophisticated way of doing it.

Rich Bradshaw
Thanks, that's so simple :P
Sam
+1  A: 

Since you're using .htaccess to redirect errors to a custom error handler file, you can use $_SERVER['REDIRECT_STATUS'] to obtain the HTTP error code. Based on that, you can display a different message depending on the error code.

htw