0

由于我的 Apache mod_expires 已启用,浏览器缓存不起作用。我已经通过 Loaded Modules 下的 phpinfo() 检查了这一点

以下是我在 htaccess 中的代码

<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/x-javascript "access plus 216000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
        Header set Cache-Control "max-age=2692000, public"
    </FilesMatch>
    <FilesMatch "\\.(css)$">
        Header set Cache-Control "max-age=2692000, public"
    </FilesMatch>
    <FilesMatch "\\.(js)$">
        Header set Cache-Control "max-age=2692000, private"
    </FilesMatch>
    <FilesMatch "\\.(x?html?|php)$">
        Header set Cache-Control "max-age=600, private, must-revalidate"
    </FilesMatch>
    Header unset ETag
    Header unset Last-Modified
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|JPG|js|pdf|png|svg|swf|tif|tiff)$">
        Header set Last-Modified "Mon, 27 Aug 2012 00:00:00 GMT"
    </FilesMatch>
</IfModule>
4

1 回答 1

0

检查此代码是否有效

<IfModule mod_headers.c>
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|swf|woff)$">
  Header set Cache-Control "max-age=2678400, public"
</filesmatch>
<filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
<filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
</filesmatch>
<filesmatch "\.(js|css)$">
  Header set Cache-Control "max-age=604800, private"
</filesmatch>

于 2016-05-30T19:56:41.543 回答