Reason, why i need disable cache:
When i create post or page. It caches its. If i create second post or page, then it updates old post or page. When i disabled cache for each pages, this bug was fixed. Although i need cache for SEO.
So, i need disable cache only in admin pages.
.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');
}
My code in function.php don't working.
从.htacess删除此行
Header set Cache-Control “max-age=86400, public”
I'm afraid that any cache headers set in .htaccess have priority, and it is impossible to override them in PHP.
The only solution that I can think of is to disable the caching setup in the .htaccess and manually set the headers in each file. It's a pain, I know, but it's all that I can fathom.
The below answer will set caching to the browser default, which I assume is not what you intend.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.