1

All requests go through index.php, and if content was not found I do:

header("HTTP/1.0 404 Not Found");
exit;

and expect to see contents of /404 as defined in .htaccess: ErrorDocument 404 /404

The problem is that I see a blank page on Chrome and Firefox, but on IE see its 404 page (not mine, browsers 404 page).

Sending header is not enough to handle redirect, so it's expected to be done by .htaccess, but fails. Should I redirect it whith PHP like so:

header("HTTP/1.0 404 Not Found");
header("Location: " . $dirpath . "404"); 
4
  • Sounds like your /404 is a 404 and therefore your 404 is 404ing. Commented Mar 21, 2014 at 19:57
  • No, you don't need to send a Location, that will not produce a correct 404 result. I don't think that you can set ErrorDocument to a folder, it need to be an actual file to execute. /404/index.php, for example. Commented Mar 21, 2014 at 19:58
  • It's not a folder, all my requests are .htaccessed to index.php and urls are rewriten. Anyway setting it to ErrorDocument 404 /index.php gives same result as described in question Commented Mar 21, 2014 at 20:04
  • Use ErrorDocument 404 /index.php and then within index.php you need to handle paths that don't exist. Commented Mar 21, 2014 at 20:41

1 Answer 1

1

No ErrorDocument 404 won't work on your way out from PHP. That is only applicable when Apache detects 404 for an incoming request and ends up invoking ErrorDocument 404 handler.

Once control is handed over to PHP as normal request processor Apache just returns output returned by PHP module to a requesting client.

Only thing you can do is this:

require_once("404.php"); // include 404 handler
exit;

And inside 404.php you can do:

http_response_code(404); // sends 404 status to browser
Sign up to request clarification or add additional context in comments.

12 Comments

Read first sentence of my answer :)
But I do RewriteCond %{HTTP_HOST} ^www\.(([^\.]+))\.pl [NC] RewriteRule ^(.*)$ http://%1.pl%{REQUEST_URI}
that rule is for www removal and has nothing to do with ErrorDocument
Sorry, I meant: RewriteRule . /index.php [L]
Ok that rule is just sending every request to /index.php
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.