【发布时间】:2022-01-08 21:23:24
【问题描述】:
我正在尝试将 HTTP STATUS 的 404 和 403 更改为 200 OK
使用 PHP,这很容易做到,但问题是我的网站是 .html,由于某种原因我无法将其更改为 .php。
代码(PHP):
header("Status: 200 OK");
我想在.htaccess 上也一样。因此它会自动将 HTTP 响应代码更改为 200 Ok 用于 404 和 403。
Htaccess 代码:
RewriteEngine On
#ErrorDocument
ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html
# Disable directory browsing
Options -Indexes
#Change status code to 200 OK
<IfModule mod_headers.c>
<If "%{REQUEST_STATUS} in { '404','403', '500' }">
Header set HTTP/1.1 "200 OK"
Header set HTTP/2 "200 OK"
</If>
</IfModule>
【问题讨论】:
-
目前您的 .htaccess 中的 404 设置如何?
-
@nice_dev
ErrorDocument 404 /notfound.html像这样 -
因此,如果找不到某个 URL,则返回
notfound.html。为除了 404 之外在服务器上找不到的文档发送 200 状态的原因可能是什么? -
@nice_dev 是的,如果内容或 URL 不存在,那么它返回
notfound.html和404响应代码,我希望它覆盖404响应代码到200 OK跨度> -
@nice_dev 明白了。我会等待你的回复。感谢您的帮助:)
标签: php apache .htaccess mod-rewrite httpresponse