wordpress - 如何仅在 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 不使用index.html
. 它使用index.php
你可以像这样改变你的比赛:
<FilesMatch "^(index\.[a-z0-9]+)?$">
[a-z0-9]+)?
匹配索引文件上的任何扩展名- 添加
?
使索引文件成为可选的,这样当索引文件是隐含的而不是在 URL 中出现时,规则可能会匹配主页。
推荐阅读
- phpstorm - PhpStorm - 标签名称中的空格问题(2020.3 版)
- java - 你如何转换地图
与杰克逊一起进入 {"keyprop" : key, "valueprop" : value} 的数组? - clojure - 如何正确检查 Java Interop 中的布尔值?
- sql - SQL 函数创建
- git - git double change,大小写相同的文件名
- javascript - Django:jQuery触发表单提交onchange of checkbox并保留重新加载时的值
- c# - 当桌面区域更改时,Appbar 会移动
- php - 使用 mysqli_connect() 创建到 mysql 的远程连接
- tableau-api - 如何使用自定义 JOIN 计算仅返回值的最后两个单词?
- c# - 为什么无法识别字母“Ñ”?