.htaccess - 如何在 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 头的正确方法是什么?
解决方案
这是Apache 的语法(为了便于阅读,我缩短了完整路径):
<Files index.html>
Header add Link "</theme...fe.woff2>; rel=preload; as=font; crossorigin"
</Files>
请注意,您还需要crossorigin
为字体添加属性 - 由于各种原因:-)
推荐阅读
- python-3.x - 是否可以使用 Python 修改文本对象的内容?
- javascript - 使用jss悬停时如何更改另一个类的可见性
- python - 是否可以使用请求从 chrome 工具 > 网络 > 预览中获取数据?
- javascript - Vuejs,如何将道具传递给路由器渲染的组件?
- java - 如何在不知道之前的类的情况下使用 CSV HeaderColumnNameTranslateMappingStrategy
- android - 带有 CHANNEL_IN_STEREO 的 Android AudioRecord 读取原始音频缓冲区导致左右音频混合
- javascript - 如何从对象数组中过滤空值?
- python - 将Unix时间戳转换为时间戳,包括某个时区的本地时间
- php - PHP图像裁剪在xampp(开发机器)上工作,但在实时服务器上运行时页面崩溃
- python - 如何迭代行以查找熊猫中列的常量值