.htaccess - 添加过期标题和.htaccess

我正在尝试根据我从GTmetrix获得的报告来优化我的WordPress网站-Type & Music。建议我做的一件事情是添加expires header 并利用浏览器缓存。我可能是错的,但我想这些都是一样的吗?

无论如何,我一直在看在线教程,例如How to Add Far Future Expires Headers to Your WordPress Site和如何通过Thomas Griffen Media的.htaccess通过WordPress利用WordPress中的浏览器缓存,这些似乎都只是复制和粘贴的情况(我知道这些设置是特定的到每个站点,这取决于您更新/编辑某些内容和文件的频率),但是当我重新测试该站点时,这些设置似乎根本没有注册。

这是我的.htaccess文件的内容:

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month”
ExpiresByType image/jpeg "access 1 month”
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 week”
ExpiresByType text/css "access 1 week”
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 week"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

此后,我也安装了Quick Cache插件,但据我所知,这并没有真正的冲突,特别是因为htaccess文件中的设置并未首先注册。

任何帮助将不胜感激,因为我自己也找不到任何帮助。

最佳答案

这是您需要添加到.htaccess文件中的工具,才能摆脱此问题。这是大多数文件类型的整个脚本。希望这可以帮助。

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType text/html "access plus 3 days"
    ExpiresByType text/xml "access plus 1 seconds"
    ExpiresByType text/plain "access plus 1 seconds"
    ExpiresByType application/xml "access plus 1 seconds"
    ExpiresByType application/rss+xml "access plus 1 seconds"
    ExpiresByType application/json "access plus 1 seconds"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-javascript "access plus 1 week"
    ExpiresByType image/x-ico "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType application/pdf "access plus 1 month"
  <IfModule mod_headers.c>
       Header unset ETag
       Header unset Pragma
       Header unset Last-Modified
       Header append Cache-Control "public, no-transform, must-revalidate"
       Header set Last-modified "Tue, 1 Oct 2014 10:10:10 GMT"
  </IfModule>
</IfModule>