gpt4 book ai didi

apache - 如何使用 .htaccess 提供 gziped 字体? (没有 mod gzip 或 deflate)

转载 作者:可可西里 更新时间:2023-11-01 01:10:38 25 4
gpt4 key购买 nike

这是我尝试过的随机顺序的列表:

AddHandler application/x-httpd-php .otf
AddType
default_mimetype
auto_prepend_file = "otf.php"
zlib.output_compression = On
output_handler = ob_gzhandler
header("Content-type: application/octet-stream");

即使服务器的所有 PHP 文件都使用 zlib 压缩,将 .otf 扩展名替换为 .php 也不起作用。

最佳答案

使用 .htaccess,你可以这样做,假设字体文件是 fontfile.otf.gz,浏览器请求它作为 fontfile.otf

RewriteEngine On

#Check for browser's Accept-Encoding, remove it for force return gzipped one
RewriteCond "%{HTTP:Accept-Encoding}" "gzip.*deflate|deflate.*gzip"

#check file name is endswith otf
RewriteCond %{REQUEST_FILENAME} "\.(otf)$"

#check existance of .gz file name
RewriteCond %{REQUEST_FILENAME}.gz -s

#rewrite it to .otf.gz
RewriteRule ^.*$ %{REQUEST_URI}.gz [L]

#update some response header
<FilesMatch "\.otf\.gz$">
AddEncoding gzip .gz
ForceType "text/plain"
</FilesMatch>

如果字体文件和网站是跨域的,你需要放Access-Control-Allow-Origin,firefox不会加载font objects cross-domain .

In Gecko, web fonts are subject to the same domain restriction (font files must be on the same domain as the page using them), unless HTTP access controls are used to relax this restriction.

Header set Access-Control-Allow-Origin *

关于apache - 如何使用 .htaccess 提供 gziped 字体? (没有 mod gzip 或 deflate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2042052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com