I am using mod_rewrite in my PHP framework to redirect user-friendly links to one main entry point of the application. The .htaccess file I am using looks like that:
<IfModule mod_rewrite.c>
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
Now, I would like to use that rule with the ErrorDocument
directive. How should I do this? My framework sets the response code to 404
when there's a controller missing:
/**
* Sets the HTTP response code.
*
* @param int $errorCode The response code to return. <b>Supported codes: </b>301, 307, 400, 401, 403, 404, 500,
* 501, 502, 503
*/
function setHTTPStatus($errorCode) {
$httpStatusCodes = array(301 => 'Moved Permanently', 307 => 'Temporary Redirect', 400 => 'Bad Request',
401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error',
501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable');
if (array_key_exists($errorCode, $httpStatusCodes)) {
header("HTTP/1.0 $errorCode $httpStatusCodes[$errorCode]", true, $errorCode);
exit;
}
}
I tried adding the line ErrorDocument 404 /index.php?url=404
and ErrorDocument 404 /error
but none seem to have worked and I get the default browser's error page.
What is wrong?
Thank you.