.htaccess htaccess中的错误文档

.htaccess htaccess中的错误文档,.htaccess,.htaccess,我正在尝试将ErrorDocument(找不到页面)添加到我的网站。 我有errorpage.php <?php http_response_code(404); ?> ... <h1>page not found</h1> 如果我打开一个不存在的页面,如:“www.example.com/xxx”,我会被重定向到:“www.example.com/errorpage.php”,但状态代码为: 302 found 404 not found 这很糟糕,

我正在尝试将ErrorDocument(找不到页面)添加到我的网站。 我有errorpage.php

<?php
  http_response_code(404);
?>
...
<h1>page not found</h1>
如果我打开一个不存在的页面,如:“www.example.com/xxx”,我会被重定向到:“www.example.com/errorpage.php”,但状态代码为:

302 found
404 not found
这很糟糕,我只需要状态码“404未找到”。
为什么我会得到两个状态码,并从“已找到”重定向到“未找到”?

也许您的请求是非www的,首先将302重定向到www,然后从errorpage.php获取http404状态,删除主机并进行检查。您还可以将这些行移到.htaccess文件的顶部。也许会有帮助

ErrorDocument 404 /errorpage.php
ErrorDocument 500 /errorpage.php

我必须添加另一个重写条件:

RewriteCond %{REQUEST_URI} .!errorpage\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$  /$1.html [QSA,L]

ErrorDocument 404 /errorpage.php
ErrorDocument 500 /errorpage.php

即使我完全清空我的htaccess文件,也是同样的问题。404之前总是有302。我在带有xampp的localhost和apache(在线)服务器上测试了它。因为您使用的是绝对URL,手册明确说明您将获得重定向。如果你不想,请使用本地URL路径。谢谢你的帮助。
RewriteCond %{REQUEST_URI} .!errorpage\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$  /$1.html [QSA,L]

ErrorDocument 404 /errorpage.php
ErrorDocument 500 /errorpage.php