How to use gziped font using .htaccess? (without mod gzip or deflate)

Here is a list of things I tried randomly:

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");

Although all PHP files on the server get gzipped using zlib, replacing the .otf extension with .php does not work either.

+3
source share
1 answer

With .htaccess you can do it like this if the font file fontfile.otf.gzis a browser request that is likefontfile.otf

RewriteEngine On

#Check for browser 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>

And if the font file and the website are cross-domain, you need to install Access-Control-Allow-Origin, firefox will not load cross-domain font objects .

Gecko - ( , ), HTTP- .

Header set Access-Control-Allow-Origin *
+4

Source: https://habr.com/ru/post/1728037/


All Articles