{"id":41481,"date":"2014-07-08T16:23:04","date_gmt":"2014-07-08T10:53:04","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=41481"},"modified":"2026-10-13T20:45:33","modified_gmt":"2026-10-13T15:15:33","slug":"vary-accept-encoding-header-with-htaccess","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/","title":{"rendered":"How to Add Vary: Accept-Encoding Header (.htaccess, Nginx, WordPress)"},"content":{"rendered":"<p>Seeing a &#8220;Specify a Vary: Accept-Encoding header&#8221; warning, or setting up compression on your server? The <strong>Vary: Accept-Encoding<\/strong> HTTP header tells browsers, proxies and CDNs that your server sends different versions of a file depending on whether the visitor supports compression such as gzip or Brotli. Without it, a cache could serve a compressed file to a browser that can&#8217;t read it. Here&#8217;s how to add the Vary: Accept-Encoding header with .htaccess, Nginx or WordPress in 2026, and how to check it&#8217;s working.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-63409\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-header.webp\" alt=\"Vary: Accept-Encoding header in HTTP response\" width=\"1200\" height=\"630\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-header.webp 1200w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-header-300x158.webp 300w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-header-1024x538.webp 1024w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-header-150x79.webp 150w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-header-768x403.webp 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p><strong>Quick answer:<\/strong> On Apache or LiteSpeed, add <code>Header append Vary Accept-Encoding<\/code> inside an <code>&lt;IfModule mod_headers.c&gt;<\/code> block in your .htaccess file. On Nginx, add <code>gzip_vary on;<\/code>. Most modern hosts, CDNs and caching plugins already send it automatically, so check first.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6ae3ea9405dc7\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #1a202c;color:#1a202c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #1a202c;color:#1a202c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6ae3ea9405dc7\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Check_if_your_site_sends_Vary_Accept-Encoding\" >Check if your site sends Vary: Accept-Encoding<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Add_Vary_Accept-Encoding_with_htaccess_Apache_and_LiteSpeed\" >Add Vary: Accept-Encoding with .htaccess (Apache and LiteSpeed)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Add_Vary_Accept-Encoding_on_Nginx\" >Add Vary: Accept-Encoding on Nginx<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#WordPress_caching_plugins_and_CDNs\" >WordPress, caching plugins and CDNs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Why_the_Vary_header_matters\" >Why the Vary header matters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Frequently_asked_questions\" >Frequently asked questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Is_Vary_Accept-Encoding_still_needed_in_2026\" >Is Vary: Accept-Encoding still needed in 2026?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Does_Vary_Accept-Encoding_work_with_Brotli\" >Does Vary: Accept-Encoding work with Brotli?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2014\/07\/vary-accept-encoding-header-with-htaccess\/#Should_images_have_a_Vary_Accept-Encoding_header\" >Should images have a Vary: Accept-Encoding header?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Check_if_your_site_sends_Vary_Accept-Encoding\"><\/span>Check if your site sends Vary: Accept-Encoding<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-41535\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding.png\" alt=\"checking Vary Accept-Encoding header\" width=\"414\" height=\"193\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding.png 414w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-150x69.png 150w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/vary-accept-encoding-300x139.png 300w\" sizes=\"(max-width: 414px) 100vw, 414px\" \/><\/p>\n<ul>\n<li>Use a free HTTP header checker such as <a href=\"https:\/\/redbot.org\/\" target=\"_blank\" rel=\"noopener\">REDbot<\/a> and look for <code>Vary: Accept-Encoding<\/code> and <code>Content-Encoding: gzip<\/code> or <code>br<\/code>.<\/li>\n<li>In Chrome, open <strong>DevTools (F12) \u2192 Network<\/strong>, reload the page, click the first request and look under <strong>Response Headers<\/strong>.<\/li>\n<li>From a terminal: <code>curl -I -H \"Accept-Encoding: gzip, br\" https:\/\/example.com\/<\/code><\/li>\n<\/ul>\n<p>For example, this site currently returns <code>content-encoding: br<\/code> (Brotli) with <code>vary: Accept-Encoding<\/code>, set automatically by our LiteSpeed server.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Add_Vary_Accept-Encoding_with_htaccess_Apache_and_LiteSpeed\"><\/span>Add Vary: Accept-Encoding with .htaccess (Apache and LiteSpeed)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The .htaccess file is in your site&#8217;s root folder and can be edited through your host&#8217;s File Manager or FTP. It&#8217;s a powerful file, and a mistake can take your site down, so always keep a backup first.<\/p>\n<pre><code>&lt;IfModule mod_headers.c&gt;\r\n  Header append Vary Accept-Encoding\r\n&lt;\/IfModule&gt;<\/code><\/pre>\n<p>Use <code>Header append<\/code> rather than <code>Header set<\/code>. <code>set<\/code> replaces any existing Vary values (such as <code>Origin<\/code> for CORS or <code>User-Agent<\/code>), while <code>append<\/code> adds Accept-Encoding without removing them. The <code>IfModule<\/code> wrapper means the line is simply skipped if mod_headers isn\u2019t enabled, instead of causing a 500 error.<\/p>\n<p>If you enable compression yourself with <code>mod_deflate<\/code> or <code>mod_brotli<\/code>, Apache adds the Vary header automatically for compressed responses. See the <a href=\"https:\/\/httpd.apache.org\/docs\/current\/mod\/mod_headers.html\" target=\"_blank\" rel=\"noopener\">Apache mod_headers documentation<\/a> for details.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Add_Vary_Accept-Encoding_on_Nginx\"><\/span>Add Vary: Accept-Encoding on Nginx<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code>gzip on;\r\ngzip_vary on;\r\ngzip_types text\/css application\/javascript application\/json image\/svg+xml;<\/code><\/pre>\n<p>The <a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_gzip_module.html#gzip_vary\" target=\"_blank\" rel=\"noopener\">gzip_vary directive<\/a> adds <code>Vary: Accept-Encoding<\/code> whenever gzip is active. Reload Nginx after saving.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"WordPress_caching_plugins_and_CDNs\"><\/span>WordPress, caching plugins and CDNs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/\" target=\"_blank\" rel=\"noopener\">LiteSpeed Cache<\/a>, <a href=\"https:\/\/wp-rocket.me\/\" target=\"_blank\" rel=\"noopener\">WP Rocket<\/a> and <a href=\"https:\/\/wordpress.org\/plugins\/w3-total-cache\/\" target=\"_blank\" rel=\"noopener\">W3 Total Cache<\/a> handle compression and Vary headers on supported servers.<\/li>\n<li><a href=\"https:\/\/www.cloudflare.com\/\" target=\"_blank\" rel=\"noopener\">Cloudflare<\/a> and most CDNs compress files and manage Vary for you.<\/li>\n<li>Managed hosts usually enable gzip or Brotli at the server level. Ask support before editing .htaccess.<\/li>\n<\/ul>\n<p>Compression is one of the easiest ways to <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2012\/02\/increase-site-speed\/\">increase site speed<\/a>, often cutting HTML, CSS and JavaScript sizes by 70% or more.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_the_Vary_header_matters\"><\/span>Why the Vary header matters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Correct caching:<\/strong> shared caches and CDNs store separate compressed and uncompressed copies instead of serving the wrong one.<\/li>\n<li><strong>Speed audits:<\/strong> older tools like GTmetrix and PageSpeed flagged a missing Vary header. Lighthouse now focuses on whether text compression is enabled at all.<\/li>\n<li><strong>Dynamic serving:<\/strong> if you serve different HTML to mobile and desktop on the same URL, Google recommends <code>Vary: User-Agent<\/code> too, although a responsive design is better.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_asked_questions\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Is_Vary_Accept-Encoding_still_needed_in_2026\"><\/span>Is Vary: Accept-Encoding still needed in 2026?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, whenever your server compresses responses. Most servers and CDNs add it automatically, but it&#8217;s worth checking, especially with custom setups.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_Vary_Accept-Encoding_work_with_Brotli\"><\/span>Does Vary: Accept-Encoding work with Brotli?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes. It covers any compression the browser announces in its Accept-Encoding request header, including gzip, Brotli (br) and Zstandard (zstd).<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Should_images_have_a_Vary_Accept-Encoding_header\"><\/span>Should images have a Vary: Accept-Encoding header?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Not usually. JPEG, PNG, WebP and AVIF files are already compressed, so servers don&#8217;t gzip them and don&#8217;t need to vary.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seeing a &#8220;Specify a Vary: Accept-Encoding header&#8221; warning, or setting up compression on your server? The Vary: Accept-Encoding HTTP header&#8230;<\/p>\n","protected":false},"author":4,"featured_media":63409,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"default","_kad_post_title":"default","_kad_post_layout":"default","_kad_post_sidebar_id":"","_kad_post_content_style":"default","_kad_post_vertical_padding":"default","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6],"tags":[49],"class_list":["post-41481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging","tag-tutorials"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/41481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=41481"}],"version-history":[{"count":3,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/41481\/revisions"}],"predecessor-version":[{"id":65625,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/41481\/revisions\/65625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media\/63409"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=41481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=41481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=41481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}