首页 > 解决方案 > Heroku HTTP 响应代码 200,应该是 404

问题描述

我有一个网站,我目前正在另一个网络托管服务上运行,我正试图转移到 heroku。我有一个处理错误的系统,其中包含以下文件:

.ht 访问:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

DirectoryIndex /home.php

ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
ErrorDocument 503 /error.php

错误.php:

<?php
$httpc = http_response_code();
echo "Your http code is ".$httpc;
?>

例如,如果您访问一个不存在的页面,它会加载 error.php 并显示“您的 http 代码是 404”。只有它没有,它说我有一个 200 OK 代码。虽然在旧主机上,它工作得很好?heroku 处理错误的方式有什么不同还是我错过了什么?

错误页面:http
://ankhsite.herokuapp.com/error.php 测试 404 错误:http ://ankhsite.herokuapp.com/thisdoesnotexist

编辑:我也刚刚意识到这一点,但在 heroku 日志中我什至可以直观地看到它给出了 404 错误。

404错误??????

标签: php.htaccesshttpherokuerror-handling

解决方案


推荐阅读