wordpress 如何禁用/wp-admin/* 中的缓存

mdfafbf1  于 2023-08-03  发布在  WordPress
关注(0)|答案(3)|浏览(180)

原因,为什么我需要禁用缓存:
当我创建文章或页面。它缓存了它的。如果我创建第二个帖子或页面,则它会更新旧帖子或页面。当我禁用每个页面的缓存时,这个错误被修复了。虽然我需要缓存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>

字符串
function.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不工作。

juzqafwq

juzqafwq1#

恐怕在.htaccess中设置的任何缓存头都有优先级,在PHP中不可能覆盖它们。
我能想到的唯一解决方案是禁用.htaccess中的缓存设置,并手动设置每个文件的头文件。我知道这很痛苦,但这是我所能理解的。
下面的答案会将缓存设置为浏览器默认值,我假设这不是您想要的。

mv1qrgav

mv1qrgav2#

从.htacess中删除此行

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

字符串

fivyi3re

fivyi3re3#

从.htacess中删除这些行

<filesMatch "\.(html|htm|php)$">
  Header set Cache-Control "max-age=1800, private, must-revalidate"
</filesMatch>

字符串
你只需要像下面这样的线条

<IfModule mod_expires.c>
AddType application/font-woff2 .woff2
AddType application/x-font-opentype .otf
ExpiresActive On
ExpiresDefault A0
ExpiresByType video/webm A10368000
ExpiresByType video/ogg A10368000
ExpiresByType video/mp4 A10368000
ExpiresByType image/webp A10368000
ExpiresByType image/gif A10368000
ExpiresByType image/png A10368000
ExpiresByType image/jpg A10368000
ExpiresByType image/jpeg A10368000
ExpiresByType image/ico A10368000
ExpiresByType image/svg+xml A10368000
ExpiresByType text/css A10368000
ExpiresByType text/javascript A10368000
ExpiresByType application/javascript A10368000
ExpiresByType application/x-javascript A10368000
ExpiresByType application/font-woff2 A10368000
ExpiresByType application/x-font-opentype A10368000
ExpiresByType application/x-font-truetype A10368000
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>

<ifModule mod_headers.c>
  <filesMatch ".(jpg|jpeg|png|gif|ico|svg|css|js)$">
Header set Cache-Control "max-age=31536000, public"
  </filesMatch>
</ifModule>

相关问题