I am establishing a website utilizing a php bootstrap. It appears the ErrorDocument directives are quit in preference for that RewriteRule's. That's ok though, the headers continue to be sent properly, and so i guess I must monitor them within the php and redirect towards the correct error document by hand. The issue though is the fact that while before I had been delivering a couple of specific errors to custom pages and also the relaxation wound up with the default apache error message, now, I can tell the way i can redirect my specific pages, however i lose all of the default messages. I can not add support for those possible errors. And, I've not attempted it, however i guess this can extend to redirect status codes too, something which I'll require because this website is changing a classic one on a single server.

What's the correct approach to take relating to this? I am wishing I am just doing a problem during my .htaccess, the salient areas of which follow:

# .htaccess

# redirect error documents - commented since they don't work anyway
# ----------------------------------------------------------------------
#ErrorDocument 404 /error/404/
#ErrorDocument 403 /error/403/
#ErrorDocument 401 /error/401/
#ErrorDocument 500 /error/500/

# Redirect to bootstrap
# ----------------------------------------------------------------------
RewriteEngine on
RewriteBase /
RewriteRule !\.(ico|jpg|png|svg|js|css)$ index.php

# Prevent hotlinking 
# ----------------------------------------------------------------------
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?.*\.mysite\.net/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(ico|jpg|png|svg|js|css)$ - [F]

Interesting help.

Good question, we arrange it through PHP.

We make use of a proprietary framework that people built. There exists a table that consists of all of the valid web addresses, or "Routes" (similar to in code igniter or kohana). We all do a couple of things.

Setup the htaccess to ensure that if your file is available around the physical server, then reveal that file. therefore the htaccess looks something similar to this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?r=$1 [L,QSA] 

explanation - rewrite any url, for example www.domain.com/myurl to visit index.php?r=myurl, except once the url is really a file (!-f) or perhaps a directory (!-d) that is available around the server.

Only then do we have our bootstrap file, index.php make a move such as this:

$route = $_GET['r'];
db::where('route', $route);
$result = db::get('routes')->fetch();
if(!$result) show_error('404');

therefore we have defined show_error('404') as

function show_error($type){
  case '404':
    header("HTTP/1.0 404 Not Found");

By using this technique, the majority of the other errors, like 403 no access etc. it's still offered from apache. If there's your password protected directory, for instance, then your rewrite may cause the server to show that directory, that will then request for any password, and when no valid the first is provided it'll serve the 403.

Best of luck!

The ErrorDocument directives are configuration choices for Apache, it uses when delivering some type of error code. Should you redirect all visitors to PHP, it becomes PHP's responsibility to reply by having an error-document. Since PHP will not do anything whatsoever automatically, it might be your responsibility.

The correct factor to complete, would be to problem a suitable error-code using header, after which echo out whatever document you would like displayed. You should use exactly the same documents as Apache would, if you want. Simply include it. Eg.:

function respond404() {
  header("HTTP/1.0 404 Page Not Found");

So far as I understand, there's no method of getting your hands on these apache configurations from within PHP, which means you either need to by hand parse the .htaccess file, or you need to duplicate the data involving the Apache configurations as well as your PHP application. There's not that lots of error codes anyway - You only have to cover individuals within the 4xx and 5xx range. See here