原因,为什么我需要禁用缓存:
当我创建帖子或页面时。它缓存它。如果我创建第二个帖子或页面,那么它会更新旧帖子或页面。 当我为每个页面禁用缓存时,此错误已得到修复。虽然我需要缓存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中的代码不起作用。
答案 0 :(得分:0)
从.htacess
中删除此行Header set Cache-Control “max-age=86400, public”
答案 1 :(得分:0)
我担心.htaccess中设置的任何缓存标头都具有优先级,并且无法在PHP中覆盖它们。
我能想到的唯一解决方案是禁用.htaccess中的缓存设置并手动设置每个文件中的标头。我知道,这是一种痛苦,但这是我能理解的一切。
以下答案将缓存设置为浏览器默认值,我认为这不是您想要的。
答案 2 :(得分:0)
从 .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>