首页 > 解决方案 > 如何仅在 wordpress 主页上禁用缓存

问题描述

在 Wordpress 上,我想将“<strong>index.html”主页上的浏览器缓存过期设置为“<strong>0”。

以及1 周内的其余 html 文件。

我尝试使用下面的代码通过htaccess来做到这一点

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"

ExpiresByType text/html "access plus 1 week"
    <FilesMatch "^(index\.html)$">
        ExpiresActive On
        ExpiresByType text/html "access plus 0 seconds"
        Header append Cache-Control "public"
    </FilesMatch>
</IfModule>

但只有一周的设置有效:

ExpiresByType text/html "access plus 1 week"

“FilesMatch”中的这个设置完全被忽略了。

ExpiresByType text/html "access plus 0 seconds"

但是,当我尝试禁用styles.css文件而不是index.html的缓存时,代码有效。

当它在“FilesMatch” 中时,它似乎与html类型有关</p>

有人可以帮我解决这个问题吗?

标签: wordpress.htaccesscaching

解决方案


WordPress 不使用index.html. 它使用index.php 你可以像这样改变你的比赛:

<FilesMatch "^(index\.[a-z0-9]+)?$">
  • [a-z0-9]+)?匹配索引文件上的任何扩展名
  • 添加?使索引文件成为可选的,这样当索引文件是隐含的而不是在 URL 中出现时,规则可能会匹配主页。

推荐阅读