Hi folks, I am having an issue handling HTTP errors (HTTP/1.1 404, 500 etc) with Hiawatha. I have created a simple PHP error handling script that redirects a user to a custom error page, by using the configuration option
ErrorHandler = 404:/php/error.php?error_code=404
.
Here is my PHP error script:
<?php
header('Location: /error_pages/http-'.$_GET['error_code'].'.html');
?>
Which is obviously really simple but works well, but only on errors with .html files. If I try to request a .php file that is not found I don't get the custom 404 error page, instead I was getting the PHP response of a very simple 'File not found' message, so after reading around I found that I need to include the
TriggerOnCGIstatus = yes
configuration option, which, when I tried to request a non-existent .php file I get Hiawatha's default 404 error page - not my custom error page! (With .html files it will work as desired either way)
My best configuration so far is to have my configuration option as
ErrorHandler = 404:/php/error.php?error_code=404&error_message=Not%20Found
and my error.php like so:
<?php
header('Status: HTTP/1.1 '.$_GET['error_code'].' '.$_GET['error_message'].'');
?>
<html>
<head>
<meta http-equiv="refresh" content="0;URL=error_pages/http-<?php echo $_GET['error_code']?>.html">
</head>
<body>
</body>
</html>
but this is a crappy option as it brute redirects the page and many people (as I do) set up the browser to stop auto redirects.
Any help on this? I have basically tried;
1. Using
TriggerOnCGIstatus = yes
2. Not using
TriggerOnCGIstatus = yes
3. Everything as above
4. Using PHP's
include('error_pages/http-'.$GET['error_code'].'.html');
It would seem nothing works, except the
http-equiv="refresh"
, but I suspect that there is a fairly simple way to resolve this issue.
Many thanks in advance