0

我正在尝试通过我的 VPS 服务器上的 .htaccess 规则设置缓存。我确保安装了 mod_expires 和 mime 类型检测,但是当我通过 gtmetrix 运行我的网站时,它显示我没有启用缓存。这是我的 .htaccess 规则:

# Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>

# Cache-Control Headers
<ifModule mod_headers.c>
#month
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
#week
  <filesMatch "\.(css|js)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
#day
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=43200, private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers

# Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None

# Remove Last-Modified Header
<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>
4

1 回答 1

0

尝试在 FilesMatch 块中添加 Last-Modifed。像这样的东西:

<FilesMatch "\.(jpg|jpeg|png|gif|js|css|ico)$">
  ExpiresDefault "access plus 10 years"
  Header  set Cache-Control "public"
  Header  set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT"
  Header  unset ETag 
  Header  append Cache-Control "max-age=604800, public"
</FilesMatch >
于 2013-01-19T21:46:06.647 回答