Yeah, from what I’ve read there’s no easy answer for 302 logs in Apache for mod_rewrite. This fix does address the problem of error pages being marked as a 302 instead of a 404. However, the fix I presented isn’t 100% complete. I did a little more investigating and found out that you almost have to explicitly define a 404 before redirecting to the actual error page. So, I felt perhaps a modest change to the sendRedirect function was in order in the document.parser.class.inc.php file. Here’s what I’ve done:
Around line 101:
if($type==REDIRECT_REFRESH) {
$header = 'Refresh: 0;URL='.$url;
} elseif($type==REDIRECT_META) {
$header = '<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$url.'" />';
echo $header;
exit;
} elseif($type==REDIRECT_HEADER || empty($type)) {
$header = 'Location: '.$url;
}
header($header);
Replace with:
if($type==REDIRECT_REFRESH) {
$header = 'Refresh: 0;URL='.$url;
} elseif($type==REDIRECT_META) {
$header = '<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$url.'" />';
echo $header;
exit;
} elseif($type==REDIRECT_ERROR) {
header("HTTP/1.0 404 Not Found");
header("Refresh: 0; URL=".$url, 0);
exit;
} elseif($type==REDIRECT_HEADER || empty($type)) {
$header = 'Location: '.$url;
}
header($header);
Basically, I added a REDIRECT_ERROR type that forces a 404 into the header then redirects to the error page. Now all we need to do is change the call to the function to include the error type like so:
Around line 119:
function sendErrorPage() {
// invoke OnPageNotFound event
$this->invokeEvent('OnPageNotFound');
$this->sendRedirect($this->makeUrl($this->config['error_page'],'','&refurl='.urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'])), 1);
}
Change to:
function sendErrorPage() {
// invoke OnPageNotFound event
$this->invokeEvent('OnPageNotFound');
$this->sendRedirect($this->makeUrl($this->config['error_page'],'','&refurl='.urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'])), 1,REDIRECT_ERROR);
}
Make these changes then attempt to visit a page that doesn’t exist. You’ll still be redirected to your error page and the error page itself will still have a 200 OK header...but look at the Apache logs. When the attempt is made to visit the non-existent page, Apache will log it properly with a 404 now. Without this change, Apache will label it as a 302 redirect.