I've got a couple of ErrorDocument directives during my .htaccess file to be able to catch the majority of the possible errors Apache can throw in a user, and also to redirect stated user to my error controller which may then render the mistake inside a easier to use manner. However, it doesn't appear work.

For example, after i enter an invalid URL like mysite.com/""##$##$! I usually get Apache's default 403 error message, rather than a redirect to my errors.php file. Below may be the directive I am using. Should i do other things to really make it work? (AllowOverride All is placed)

   ErrorDocument 403 /errors.php

If this sounds like the wrong manner to approach absolute custom error handling, please tell me, I'd appreciate a nudge within the right direction.


Edit: Oh, just thought I'd mention this. I authored my very own MVC structure for redirecting the request, and delay pills work well. From inside PHP, if your user demands a nonexistant URL, my very own 404 error will fire all right (or whatever other error I've defined). So essentially, basically enter mysite.com/!!!! in to the URL, it'll work and that i obtain a 404. However, whenever I begin a request using the double quote character, the default Apache 403 error fires. Odd. Also, a 500 error will neglect to redirect to errors.php too, and can simply return a default Apache 500 screen (for example, when testing with header("HTTP/1. 500 Internal Server Error")die()).

Edit 3: I simply attempted placing ErrorDocument 200 "message" during my .htaccess file and absolutely nothing happened, any page I open opens normally. Worst situation scenario, this will really go to town an infinite loop. Best situation scenario, it will output "message". It did neither, it really overlooked ErrorDocument. Apache's Access Log notes an ordinary 200 OK header, but it had been completely overlooked by .htaccess.

A couple of different mis-conceptions within the question. The next PHP code:

header("HTTP/1.0 500 Internal Server Error");

Won't ever trigger an Apache error page - it's triggering your browser's default error page. Once control continues to be given to PHP, it doesn't return to Apache for error handling.

ErrorDocument only works best for error codes, not success codes. It's within the paperwork

Syntax: ErrorDocument error-code document


Should you be mistaking one type of browser error page for any server error, then that may be the reason for your primary problem too. Unless of course your custom error handler results some data, some browsers will invariably show their very own error pages. Make certain your output reaches least a couple of kilobytes in dimensions.

The reason for your condition is probably just Apache's built-in behavior coupled with the selection of test Web addresses. In the ErrorDocument paperwork:

Although most error messages could be overriden, you will find certain conditions in which the internal messages are utilized no matter the setting of ErrorDocument. In particular, if your malformed request is detected, normal request processing is going to be immediately stopped and also the internal error message came back. This is essential to protect against security problems triggered by bad demands.

Edit: How you can simulate a 500 error in Apache. My first thought was syntax errors in .htaccess, but this wont trigger custom error handlers. The simplest way I discovered ended up being to enable CGI in .htaccess with the addition of wrinkles:

ErrorDocument 500 /500.php
Options +ExecCGI
AddHandler cgi-script .pl

After which adding a perl script that crashes:


You will have to make certain the perl script is executable by apache's user. This shows my custom 500 handler.

However, you are most unlikely to ever trigger an Apache 500 when utilizing PHP, which means this most likely is not a helpful test.

I simply use .htaccess for those custom error pages

ErrorDocument 401 /error/PHP/server-error.php?error=401

ErrorDocument 403 /error/PHP/server-error.php?error=403

ErrorDocument 404 /error/PHP/server-error.php?error=404

ErrorDocument 500 /error/PHP/server-error.php?error=500

ErrorDocument 503 /error/PHP/server-error.php?error=503