通过 htaccess 禁用 Apache http2 公告

Disable Apache http2 announce via htaccess

我在共享主机上有一个网站,在每个页面请求中使用这些 HTTP header 响应:

HTTP/1.1 200 OK
Date: Thu, 21 Sep 2017 14:34:46 GMT
Server: Apache
X-Powered-By: PHP/5.6.31
Access-Control-Allow-Origin: *
Upgrade: h2,h2c
Connection: Upgrade, Keep-Alive
Keep-Alive: timeout=5, max=400
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

如您所见,Upgrade header 是 Apache 关于支持 HTTP2 协议的公告。

出于某种原因,我需要禁用 Apache 的这种行为,以便在没有 Upgrade header.

的情况下发送响应

谁知道如何从 .htaccess 文件中禁用它? 我已经找到了这个解决方案:

Header unset Upgrade

但这不是很好,因为有时我需要从我的代码中输出自定义 Upgrade header(需要向某些热敏打印机设备广播固件升级)。

谢谢

尝试使用此配置将其关闭:https://httpd.apache.org/docs/2.4/mod/mod_http2.html#h2upgrade

或者,对于仅 .htaccess 的解决方案,使用 Header edit 功能:

Header edit Upgrade (.*)h2,h2c(.*) ""

请注意,这可能会给您带来空升级 header,并且您可能必须根据服务器显示的内容(例如额外的逗号)更改配置。