【问题标题】:Specify a Vary: Accept-Encoding header: for (siteground hosting)指定一个 Vary: Accept-Encoding header: for (siteground hosting)
【发布时间】:2018-05-02 09:38:57
【问题描述】:

这是我的 .htaccess 文件,我使用了来自 google 的超级缓存插件和 pagespeed。

# TN - START EXPIRES CACHING #
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
# TN - END EXPIRES CACHING #

# TN - BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# TN - END Cache-Control Headers

# TN - BEGIN Turn ETags Off
FileETag None
# TN - END Turn ETags Off

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN supercache
<IfModule mod_mime.c>
  <FilesMatch "\.html\.gz$">
    ForceType text/html
    FileETag None
  </FilesMatch>
  AddEncoding gzip .gz
  AddType text/html .gz
</IfModule>
<IfModule mod_deflate.c>
  SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
<IfModule mod_headers.c>
  Header set Vary "Accept-Encoding, Cookie"
  Header set Cache-Control 'max-age=3, must-revalidate'
</IfModule>
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html A3
</IfModule>
Options -Indexes
# END supercache

Options All -Indexes

如果我停用 cdn,我会在速度测试中出错:

以下可公开缓存、可压缩的资源应具有“Vary: Accept-Encoding”标头: https://droidawy.com/wp-content,_plugins,_mh-lo ... asonry.js,qver==4.2.1.pagespeed.jc.aJe1qC-NMI.js ttps://droidawy.com/wp-content,_themes,_mharty ... t.min.js,qver==1.11.4.pagespeed.jc.vbNvVnCSV-.js https://droidawy.com/wp-content/plugins/heateor ... ront.css,qver=1.4.12.pagespeed.cf.bcGmYWboif.css https://droidawy.com/wp-content/plugins/host-analyticsjs-local/cache/local-ga.js ttps://droidawy.com/wp-content/plugins/mh-auth ... style.css,qver=1.3.1.pagespeed.cf.sg490QkEIx.css https://droidawy.com/wp-content/plugins/mh-love ... style.css,qver=2.1.1.pagespeed.cf.IEZBYGhsBU.css ttps://droidawy.com/wp-content/plugins/mh-maga ... style.css,qver=2.0.1.pagespeed.cf.k8FUittoKh.css 包括/js/jquery/jquery.js,qver=1.12.4.pagespeed.jm.pPCPAKkkss.js https://droidawy.com/wp-includes/js/wp-emoji-release.min.js?ver=4.9

我尝试了这段代码,但没有解决:

<IfModule mod_headers.c>
  <FilesMatch ".(js|css|xml|gz|html)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

【问题讨论】:

    标签: wordpress .htaccess


    【解决方案1】:

    SiteGround 的 SuperCacher 插件(通常)不需要对您的 .htaccess 文件进行任何修改。

    删除 .htaccess 中的超级缓存条目,然后重新启用 CDN,清除 CDN 缓存,然后重试。

    附带说明,请考虑在检查器中使用 Google Chrome 的审核选项卡来测试您网站的速度,因为许多在线工具对您的托管做出了不正确的假设。特别是,许多工具针对的是 HTTP/1.1 服务器,而 SiteGround 提供 HTTP/2(在交付内容时这是一个完全不同的范例)。

    祝你好运。

    【讨论】:

    • 感谢您提供宝贵的信息,但我使用 pagespeed 来停用站点缓存,我使用 wp 超级缓存插件,所以当我停用 Cloudflare CDN 时我必须编辑 .htaccess 我觉得我的站点速度更好还有其他想法吗?
    • 我很确定 SiteGround 有它自己的插件,叫做 SuperCacher(或类似的东西)。你能检查一下它是否适用于你的帐户吗?在专用服务器上,它可以通过 cPanel 获得。请在这里告诉我。
    • 在那里,但是当我使用 pagespeed 时它会自动停用,所以我使用页面速度和 wp 超级缓存 + htaccess 利用浏览器缓存
    • 是的,我想我的“答案”并不是真正的答案,因为我建议您放弃 GPS 和 WP-Super-Cache 以换取 SiteGround 自己的 SuperCacher 插件。 SG 还提供静态缓存(就在 GPS 选项上方)。祝你好运。
    猜你喜欢
    • 2013-05-14
    • 2011-04-08
    • 2013-01-10
    • 2012-06-18
    • 2011-09-06
    • 2011-03-08
    • 1970-01-01
    • 2020-08-28
    • 2017-08-27
    相关资源
    最近更新 更多