我在我的 PHP 框架中使用 mod_rewrite 将用户友好的链接重定向到应用程序的一个主要入口点。我正在使用的 .htaccess 文件如下所示:
<IfModule mod_rewrite.c>
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
现在,我想将该规则与ErrorDocument
指令一起使用。我该怎么做?我的框架将响应代码设置为404
缺少控制器时:
/**
* 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;
}
}
我尝试添加该行ErrorDocument 404 /index.php?url=404
,ErrorDocument 404 /error
但似乎没有任何效果,并且我得到了默认浏览器的错误页面。
怎么了?
谢谢你。