首页 > 解决方案 > 如何在 /wp-admin/* 中禁用缓存

问题描述

原因,为什么我需要禁用缓存:

当我创建帖子或页面时。它缓存它的。如果我创建第二个帖子或页面,那么它会更新旧帖子或页面。当我为每个页面禁用缓存时,此错误已修复。虽然我需要 SEO 缓存。

所以,我只需要在管理页面中禁用缓存。

.htaccess

<ifModule mod_headers.c>
  <filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|woff2)$">
  Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css|js)$">
  Header set Cache-Control "max-age=86400, public"
  </filesMatch>
  <filesMatch "\.(xml|txt)$">
  Header set Cache-Control "max-age=172800, public, must-revalidate"
  </filesMatch>
  <filesMatch "\.(html|htm|php)$">
  Header set Cache-Control "max-age=1800, private, must-revalidate"
  </filesMatch>

  <FilesMatch "\.(js|css|jpg|png|jpeg|gif|xml|json|txt|pdf|mov|avi|otf|woff|ico|swf)$">
  RequestHeader unset Cookie
  Header unset Cookie
  Header unset Set-Cookie
  </FilesMatch>


  # Guarantee HTTPS for 1 Year including Sub Domains
  Header always set Strict-Transport-Security "max-age=31536000;"
</ifModule>

函数.php

if (is_admin()) {
      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
      header('Cache-Control: no-store, no-cache, must-revalidate');
      header('Cache-Control: post-check=0, pre-check=0', FALSE);
      header('Pragma: no-cache');
}

我在 function.php 中的代码不起作用。

标签: phpwordpress.htaccess

解决方案


从 .htacess 中删除此行

Header set Cache-Control “max-age=86400, public”

推荐阅读