.htaccess 过期标题不起作用

.htaccess 过期标题不起作用,.htaccess,caching,.htaccess,Caching,我尝试了几种方法让图像和其他资源有一个有效期,但没有一种方法能够满足 我还安装了W3插件,但该工具仍然报告图像没有设置expires头 我的htaccess中还包含以下代码: <IfModule mod_expires.c> ExpiresActive On ExpiresDefault A300 ExpiresByType application/x-javascript A3600 ExpiresByType text/css A3600 ExpiresByType image/

我尝试了几种方法让图像和其他资源有一个有效期,但没有一种方法能够满足

我还安装了W3插件,但该工具仍然报告图像没有设置expires头

我的htaccess中还包含以下代码:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300
ExpiresByType application/x-javascript A3600
ExpiresByType text/css A3600
ExpiresByType image/gif A3600
ExpiresByType image/png A3600
ExpiresByType image/jpeg A3600
ExpiresByType text/plain A300
ExpiresByType application/x-shockwave-flash A3600
ExpiresByType video/x-flv A3600
ExpiresByType application/pdf A3600
ExpiresByType text/html A300
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

过期于
到期默认A300
ExpiresByType应用程序/x-javascript A3600
ExpiresByType文本/css A3600
ExpiresByType图像/gif A3600
ExpiresByType图像/png A3600
过期按类型图像/jpeg A3600
ExpiresByType文本/普通A300
过期按类型应用/x-shockwave-flash A3600
ExpiresByType视频/x-flv A3600
过期按类型申请/pdf A3600
ExpiresByType文本/html A300
#开始WordPress
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
这似乎是一个常见的问题,我看到了很多关于这方面的问题,但找不到答案


问题是在测试工具中还是在我的服务器上?我怎么才能知道呢?

我也有同样的问题。似乎(某些)验证器,如YSlow,只有在过期日期为value
31536000
时才会成功

以下是完整的W3总缓存访问:。
这对我有用,你不妨试试看


注意粘贴箱不包含WordPress htaccess内容

我的答案是启用过期模块

a2enmod expires
systemctl restart apache2
答复:Southparkfan in

因此,这段代码将在apache服务器配置中工作

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    ExpiresByType text/html "access plus 15 days"
    ExpiresByType image/gif "access plus 1 months"
    ExpiresByType image/jpg "access plus 1 months"
    ExpiresByType image/jpeg "access plus 1 months"
    ExpiresByType image/png "access plus 1 months"
    ExpiresByType text/js "access plus 1 months"
    ExpiresByType text/javascript "access plus 1 months"

    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
</IfModule>

过期于
ExpiresDefault“访问加1个月”
ExpiresByType text/html“访问加15天”
ExpiresByType image/gif“访问加1个月”
ExpiresByType图像/jpg“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType图像/png“访问加1个月”
ExpiresByType文本/js“访问加1个月”
ExpiresByType文本/javascript“访问加1个月”
ExpiresByType应用程序/vnd.ms-fontobject“访问加1年”
ExpiresByType字体/ttf“访问加1年”
ExpiresByType字体/otf“访问加1年”
ExpiresByType字体/woff“访问加1年”
ExpiresByType字体/woff2“访问加1年”
ExpiresByType图像/svg+xml“访问加1年”

希望这会有所帮助

我们试图得到一个错误的结果。我也在寻找解决方案,但在阅读带有这些(expire header)代码但没有这些代码的GTMetrix测试结果后,我发现:

  • expire头代码正在工作,但仅适用于内部文件
  • expire头代码不能用于外部文件(来自其他网站,如google analytics js…)
  • 测试结果将仅显示外部文件
  • 如果删除这些代码行,结果将是最糟糕的,并且会导致更多的文件没有过期期限

为什么你认为这是一个WordPress问题?因为我使用WordPress,并认为这可能是WordPress的特定问题。也许这属于stackoverflow。早在WordPress启动之前,.htaccess就已经被读取和执行了。将移动它。使用31536000进行了尝试,但仍然相同,还尝试了粘贴库中的代码,并且相同。您可以尝试在中搜索规则和限制?thx我将尝试。那么基本上你是说测试是错误的,htaccess是有效的?有没有办法找出我的服务器是否有任何问题?我不想说这些设置是错误的,因为我对它没有任何经验。但是,您可以使用YSlow和PageSpeed Insights for Chrome测试页面,以比较不同的结果。