PHPフレームワークでmod_rewriteを使用して、ユーザーフレンドリーなリンクをアプリケーションの1つのメインエントリポイントにリダイレクトしています。私が使用している.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
が、何も機能していないようで、デフォルトのブラウザのエラーページが表示されます。
なにが問題ですか?
ありがとうございました。