首页 > 解决方案 > 如何在 htaccess 中添加 http/2 标头以推送文件

问题描述

我正在尝试通过基于 HTTP/2 指令的 HTML 标头预加载一个文件。但是在对 htaccess 文件进行任何修改后,我收到错误 500。

这是我在 htaccess 中使用的一段代码:

# add custom header to single file
<Files index.html>
    Link: </themes/PRS060142/assets/css/570eb83859dc23dd0eec423a49e147fe.woff2>; rel=preload; as=font
</Files>

有人知道通过 htaccess 发送 HTML 头的正确方法是什么?

标签: .htaccesshttphttp-headershttp2

解决方案


这是Apache 的语法(为了便于阅读,我缩短了完整路径):

<Files index.html>
    Header add Link "</theme...fe.woff2>; rel=preload; as=font; crossorigin"
</Files>

请注意,您还需要crossorigin为字体添加属性 - 由于各种原因:-)


推荐阅读