It is a knotty problem and very un-computer like, which makes it a very interesting problem, no doubt.
So let me explain what (I think) we know so far and maybe they'll be some light shed into the dark corners.
1) A straight 404 ErrorDocument statement in the .htaccess file yields sporadic results in MSIE. 80% of the time - "friendly message", 20% (or so) "custom 404.php" file.
2) At first, my host provider claimed that it was the php code, but I made my 404 error file a plain-old HTML file (>512 bytes, as per the MSIE min requirement snafu). When I did, the success RATE improved, but was STILL not 100% successful.
3) My host tried eliminating the error FILE altogether, by using error TEXT in the .htaccess file (with the same MSIE-failure results).
4) My host said, "Yeah, there's a problem, but we've not seen it before and we can't do anything for you. G'night, you're on your own."
5) A friend suggested using php to redirect MSIE traffic to another file and I tried it. (My first posts at this forum were elucidation regarding the php "header" function). But I also wanted to pass environmental variables along to the redirected session [My next posts involved learning about session_start()]. And then today, when I first posted, I was redirecting fine ONLY ON THE FIRST 404 error for a window. Type in another wrong file and I received the oft-noob error "Warning, cannot modify header info ... blah blah blah". So today, I learned about buffering [ob_start() and ob_end_flush()], which has seemingly taken care of the problem. So .. that is my solution.
a) .htaccess points to a file (call it 404.php, for grins)
b) that file gathers env info & redirects to the another (call it 404new.php), which is the REAL custom error file.
c) That 404new file collects the session variables, starts the buffer, does the script that emails me some info, pushes the 404 error message and flushes the buffer. Bing batta bam.
You can test the working version on our subdomain:
http://pct-hike.randsco.com/no-such-file.html
So far, my tests show 100% success in MSIE.
.htaccess contains only:
Code: Select all
ErrorDocument 404 /_errors/404.php
the 404.php file contains the following php code, placed at the tippy top
Code: Select all
<?php
session_start();
$_SESSION['ip'] = getenv("REMOTE_ADDR");
$_SESSION['uri'] = getenv("REQUEST_URI");
$_SESSION['srvr']= getenv("SERVER_NAME");
$_SESSION['refr']= getenv("HTTP_REFFERER");
$_SESSION['agnt']= getenv("HTTP_USER_AGENT");
header("Location: http://mysubdom/_errors/404new.php"); ?>
The redirected file contains several things, most notably, the following php at the tippy top
Code: Select all
<?php session_start();
$ipAddress = $_SESSION['ip'];
$request = $_SESSION['uri'];
$server = $_SESSION['srvr'];
$referrer = $_SESSION['refr'];
$browser = $_SESSION['agnt'];
?>
<?php ob_start(); ?>
a couple of php include statements, some other php code to format the env variables and email the information, HTML and ends with
Code: Select all
<?php include("http://randsco.com/randsFooter.ssi") ?>
<?php ob_end_flush(); ?>
immediately prior to the closing body tag.
NOTE: This solution only exists on our subdomain. Our MAIN domain is simply calling the 404.php file from within the root-level .htaccess file.
6) On our MAIN domain, I have tried using a mod_rewrite to replace the 404.php file that ErrorDocument calls, with 404new.html ... but, this yields a similar result to just using ErrorDocument without the mod_rewrite (not 100% success). No errors ... just not 100% success.
7) Feyd suggested doing away with the ErrorDocument statement and trying a 100% mod_rewrite solution. I used his posted code, inserting the fully-qualified location of my 404.php file, but received a server error code and have not pursued this further, figuring that the result would be similar to (6) and not having the immediate knowledge to track down the syntactical error.
So that's where we sit.
I'm not so sure what you're doing with the redirect that makes it work.
Me neither. I am only going on empirical data here. And for me, the larger question is "Why isn't the normal, straight-forward 'ErrorDocument-in-the-.htaccess-file' working properly?"
I suspect that there is something wonky with the SiteGround.com server setup, but because they are unresponsive to my inquiry, I have know way of eliciting their assistance.
Anyway ... I thank you for yours, fruitful or not, this remains (a) an intriguing problem and (b) a thorn in my side!
-Scott