如何使用.htaccess缓存woff文件

时间:2018-06-05 18:18:48

标签: apache .htaccess woff

我尝试使用.htaccess缓存.woff?v = 4.6.3文件,但此代码不起作用:

<ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>


<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 2 days"
  ExpiresByType image/jpeg "access plus 31104000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 3600 seconds"
  ExpiresByType application/xhtml+xml "access plus 3600 seconds"
</ifModule>

你有什么建议吗? (注意:我在Google和这个论坛上搜索解决方案,但我找不到适用的解决方案)

1 个答案:

答案 0 :(得分:0)

您可以尝试使用filesmatch指令

<IfModule mod_headers.c>
  <filesMatch ".(css|jpg|jpeg|png|gif|js|ico|woff)$">
  Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
</IfModule>