【问题标题】:How do i can disable cache in /wp-admin/*如何在 /wp-admin/* 中禁用缓存
【发布时间】:2018-06-08 07:45:00
【问题描述】:

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

当我创建帖子或页面时。它缓存它的。如果我创建第二个帖子或页面,那么它会更新旧帖子或页面。 当我为每个页面禁用缓存时,此错误已修复。虽然我需要 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 中的代码不起作用。

【问题讨论】:

    标签: php wordpress .htaccess


    【解决方案1】:

    恐怕.htaccess中设置的任何缓存头都有优先级,在PHP中不可能覆盖它们。

    我能想到的唯一解决方案是禁用 .htaccess 中的缓存设置并手动设置每个文件中的标头。这很痛苦,我知道,但这是我能理解的全部。

    以下答案会将缓存设置为浏览器默认值,我认为这不是您想要的。

    【讨论】:

      【解决方案2】:

      从 .htacess 中删除这一行

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

      【讨论】:

        【解决方案3】:

        从 .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>
        

        【讨论】:

          猜你喜欢
          • 2017-08-26
          • 1970-01-01
          • 2023-04-09
          • 1970-01-01
          • 1970-01-01
          • 2013-09-20
          • 2017-07-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多