Apache htaccess:service预压缩@font-face字体

Apache htaccess:service预压缩@font-face字体,apache,.htaccess,fonts,compression,Apache,.htaccess,Fonts,Compression,我需要Apache来提供不使用deflate的预压缩字体 /path\u to/font/文件夹中的My.htaccess如下所示 RewriteEngine On RewriteBase /path_to/fonts/ RewriteCond %{HTTP:Accept-Encoding} .*gzip.* RewriteRule (.*)\.ttf $1.ttf.gz AddEncoding x-gzip gz RemoveType application/x-gzip .gz

我需要Apache来提供不使用deflate的预压缩字体

/path\u to/font/文件夹中的My.htaccess如下所示

RewriteEngine On
RewriteBase /path_to/fonts/
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*


RewriteRule (.*)\.ttf $1.ttf.gz


AddEncoding x-gzip gz

RemoveType application/x-gzip .gz
响应标题:

内容长度显示为31709,这将是压缩大小,但我无法下载


你能给我一个提示吗?

这是我的解决办法。它大多有一点抛光

除非客户端支持gzip,否则它不会设置类型和编码。还声明所使用的模块,以便在不支持所有模块的情况下不会发生任何事情

文件夹结构:

fonts/  
  Shanti-Regular.ttf.gz  
  Federo-Regular.ttf.gz  
  Shanti-Regular.ttf  
  Federo-Regular.ttf  
  .htaccess  
那么.htaccess包含:

# Rewrite URLs to add gzipped version of font when it exits.
<IfModule mod_rewrite.c>
<IfModule mod_mime.c>
  RewriteEngine on

  #Serve gzip compressed TTF files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.ttf $1\.ttf\.gz [QSA]

  # update the response header of compressed file
  # makes browser think mod_gzip did it.
  <FilesMatch "\.ttf\.gz$">
    AddEncoding gzip .gz
    ForceType "application/x-font-ttf"
  </FilesMatch>

</IfModule>
</IfModule>

这是我的解决办法。它大多有一点抛光

除非客户端支持gzip,否则它不会设置类型和编码。还声明所使用的模块,以便在不支持所有模块的情况下不会发生任何事情

文件夹结构:

fonts/  
  Shanti-Regular.ttf.gz  
  Federo-Regular.ttf.gz  
  Shanti-Regular.ttf  
  Federo-Regular.ttf  
  .htaccess  
那么.htaccess包含:

# Rewrite URLs to add gzipped version of font when it exits.
<IfModule mod_rewrite.c>
<IfModule mod_mime.c>
  RewriteEngine on

  #Serve gzip compressed TTF files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.ttf $1\.ttf\.gz [QSA]

  # update the response header of compressed file
  # makes browser think mod_gzip did it.
  <FilesMatch "\.ttf\.gz$">
    AddEncoding gzip .gz
    ForceType "application/x-font-ttf"
  </FilesMatch>

</IfModule>
</IfModule>

text/plain似乎是错误的mime类型。但是你为什么要自己处理gzipping呢?您需要节省服务器上的CPU使用量吗?您将使用哪种mime类型?预Gzip是客户端必需的。请使用font/ttf或application/x-font-ttf。预gzipping似乎是一个愚蠢的必要条件,可能是那些在某个地方读到它对[在这里插入流行语]有好处的人所做的。看起来很浪费。就我的2美分。哦!我刚刚意识到这是压缩文件的问题。它似乎适用于text/plain和您的font/ttf或application/x-font-ttf。谢谢你的回答!text/plain似乎是错误的mime类型。但是你为什么要自己处理gzipping呢?您需要节省服务器上的CPU使用量吗?您将使用哪种mime类型?预Gzip是客户端必需的。请使用font/ttf或application/x-font-ttf。预gzipping似乎是一个愚蠢的必要条件,可能是那些在某个地方读到它对[在这里插入流行语]有好处的人所做的。看起来很浪费。就我的2美分。哦!我刚刚意识到这是压缩文件的问题。它似乎适用于text/plain和您的font/ttf或application/x-font-ttf。谢谢你的回答!