【问题标题】:Get error description with .htaccess/PHP使用 .htaccess/PHP 获取错误描述
【发布时间】:2026-01-23 12:00:02
【问题描述】:

我正在运行 apache 服务器,我希望自定义 PHP 错误页面显示错误编号和错误描述。例如,我在 .htaccess 中有:
ErrorDocument 404 /?e=404
在我的错误页面中:

<?php
$e = $_GET['e'];
if($e === 404){
?>
Error: <?=$e?>
<?php } ?>

所以它会显示:
Error: 404
但我也希望它显示描述,例如
Error: 404 Not Found
无需从 PHP 中的数据库等中提取。那么是否可以使用 .htaccess 传递参数或其他内容?

【问题讨论】:

    标签: php apache .htaccess rewrite


    【解决方案1】:

    据我所知,没有什么魔法可以为您翻译描述中的错误代码。这并不意味着你不能继续你已经走的路:

    ErrorDocument 404 /?e=404&desc=Not%20Found
    

    现在错误代码在$_GET['e'],描述在$_GET['desc']

    【讨论】: