How to serve a gziped font using .htaccess? (no mod gzip or deflate)
.htaccess, apache, php, webfonts
Solution
With .htaccess, you could do like this, assuming font file is `fontfile.otf.gz`, browser request that as `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>
And if font file and web site is cross-domain, you need to put `Access-Control-Allow-Origin`, firefox will not load 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 *
Problem
Here's a list of stuff I tried in random order: ``` 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"); ``` Even though all the PHP files of the server get gzipped using zlib, replacing the .otf extension by .php didn't work either.