You're looking for ErrorDocument
.
In your .htaccess specify the codes you want to handle, like:
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
And in error.php, handle the error codes like:
<?php
$code = $_SERVER['REDIRECT_STATUS'];
$codes = array(
403 => 'Forbidden',
404 => 'Not Found',
500 => 'Internal Server Error'
);
$source_url = 'http'.((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (array_key_exists($code, $codes) && is_numeric($code)) {
die("Error $code: {$codes[$code]}");
} else {
die('Unknown error');
}
?>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…