Forum Moderators: phranque
I have
ErrorDocument 404 [host...]
This alone works fine, and trying an invalid URL brings me the 404. THEN comes the trouble: I enable the rewriting, which consists of rewriting all requests to index.php. If index.php cannot find anything useful to do with the request, it does
header("HTTP/1.0 404 Not Found");
exit();
and I want the default 404.html page to display. But nothing happens; only a blank screen. In my access logs I get this message:
127.0.0.1 - - [18/Jul/2005:22:46:53 +0200] "GET /path/invalid_page HTTP/1.1" 404 -
Then I find a request that did bring up the 404 page (before enabeling the rewrite) and see
127.0.0.1 - - [18/Jul/2005:22:16:01 +0200] "GET /gammelt/yeah HTTP/1.1" 302 293
which isn't right either, 302 should be 404. What's going on here? And what's that 293? Thankful for any ideas.
404 error -> 404 page -> find index.php -> makes 404 error -> 404 page -> find index.php -> makes 404 error -> 404 page -> etc.
I'm not familier with the mod_rewrite function but maybe an exception to 404.html could be used or maybe a section in index.php as the 404 file
127.0.0.1 - - [19/Jul/2005:00:48:40 +0200] "GET /path/i404.html HTTP/1.1" 404 -
127.0.0.1 - - [19/Jul/2005:00:49:22 +0200] "GET /path/i404.html HTTP/1.1" 302 309
127.0.0.1 - - [19/Jul/2005:00:49:22 +0200] "GET /path/404.html HTTP/1.1" 304 -
The first request is with mod_rewrite enabled and ErrorDocument enabled. It returned a blank page, not the expected 404.html (i404.html does not exist and should be rewritten).
The second request I have disabled rewriting, so it calls for the 404.html page (third request). What bugs me about this one is that it doesn't have the 404 status, it has 302 Redirect? And what does the next number mean? 302 309? Is it possible that the first request should look like 404 309 or something?
index.php:
// parse url...
if ($url[0] == 'i404.html') {
header("HTTP/1.0 404 Not Found");
exit();
}
.htaccess:
ErrorDocument 404 [localhost...]
RewriteEngine on
RewriteRule!(\.(jpg¦gif¦css¦png)$¦^404.html$) index.php
Welcome to WebmasterWorld!
Your ErrorDocument directive is incorrect, and will produce a 302 response instead of the desired 404. See the ErrorDocument documentation [httpd.apache.org] in Apache core.
It should read:
ErrorDocument 404 /path/404.html
Jim
Ok, fixed my ErrorDocument so my .htaccess now reads:
ErrorDocument 404 /path/404.html
RewriteEngine on
RewriteRule!(\.(jpg¦gif¦css¦png)$¦/404.html$) index.php
Two last requests:
127.0.0.1 - - [19/Jul/2005:02:09:42 +0200] "GET /path/i404.html HTTP/1.1" 404 -
127.0.0.1 - - [19/Jul/2005:02:10:39 +0200] "GET /path/i404.html HTTP/1.1" 404 433
The first request has rewriting enabled and an index.php with:
if ($url[0] == 'i404.html') {
header("HTTP/1.0 404 Not Found");
exit();
}
as before. It generates the 404 but doesn't redirect, still the blank page. The second request is without rewriting showing that the ErrorPage now works as expected.
I'm still wondering about these though
404 -
404 433
What's the second number? And is the fact that it is "-" in my rewritten request causing problems? When sending the 404 header with PHP shouldn't the ErrorDocument be loaded?
Jim