如何在WordPress中排除过滤sitemap.xml缓存

2022年8月26日 924点热度 0人点赞 0条评论

如何在WordPress中排除过滤sitemap.xml缓存

 

在WordPress中安装了缓存插件的情况下,我们有时间想要让特定地址、文件不被缓存,如sitemap.xml、sitemap.txt、sitemap.html等,因为是站点地图文件,所以我们必须保持他是最新的,不被缓存的。

 

注意⚠️:不要删除配置中的原有内容,修改之后你可以想要在设置 > 固定链接 中点击修改按钮,来立即生效。

 

通过.htaccess文件控制缓存规则,不推荐

在 .htaccess 文件的最末尾行添加以下内容

RewriteEngine On
RewriteRule .* - [E=Cache-Control:no-cache]

 

 

 

在WordPress使用了W3 Total Cache 缓存插件

在Performance > Page Cache 中的 Never cache the following pages 中填入以下内容,原先的保持不变

 

sitemap(_index)?\.xml(\.gz)?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*)?\.xml

同时也可以将上述内容填写至 以下位置,最新版本可能自带了sitemap排除
Performance > Database Caching > Never Cache the Following Pages
Performance > Minify > Never minify the following Pages
Performance > Browser Cache > 404 error exception list

 

 

在WordPress使用了LiteSpeed Cache缓存插件

点击LiteSpeed Cache > Cache > Excludes 中的 Do Not Cache URIs 区域填写以下内容

/(.*)sitemap(.*).xml
/(.*)sitemap.xsl
/sitemap_index.xsl
/sitemap_index.xml

 

 

在WordPress使用了WP Rocket缓存插件

设置 > WP Rocket > Advanced Rules> Never Cache URL(s) 中添加以下内容

 

/(.*)sitemap(.*).xml
/(.*)sitemap.xsl

 

 

 

在WordPress使用了WP Super Cache缓存插件

设置 > WP Super Cache > Advanced(高级) > URL字符串被拒绝

 

sitemap?\.xml?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml

 

如何在WordPress中排除过滤sitemap.xml缓存

 

 

 

在WordPress使用了WP Fastest Cache缓存插件

在 WP Fastest Cache > Exclude 中点击 Add New Rule 来添加新规则,在下拉列表中选择包含,然后在Value字段填写sitemap,点击确认进行排除

 

 

Cloudflare缓存了sitemap

Cloudflare默认是不会缓存sitemap的,但是不排除意外,可以在Cloudflare的设置页面添加规则,

sitemap?\.xml?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml

 

 

 

在WordPress使用了Hummingbird Cache缓存插件

Hummingbird Settings > Caching > Page Caching > Activate 中URL Strings中添加以下内容

sitemap\.xml

 

 

 

 

目前只列出这么多,大多数的缓存都可以通过搜索引擎找到解决方法。

帮助教程

提供最新的帮助教程,方便使用。

文章评论