How to Add Vary: Accept-Encoding Header (.htaccess, Nginx, WordPress)
Seeing a “Specify a Vary: Accept-Encoding header” warning, or setting up compression on your server? The Vary: Accept-Encoding 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’t read it. Here’s how to add the Vary: Accept-Encoding header with .htaccess, Nginx or WordPress in 2026, and how to check it’s working.

Quick answer: On Apache or LiteSpeed, add Header append Vary Accept-Encoding inside an <IfModule mod_headers.c> block in your .htaccess file. On Nginx, add gzip_vary on;. Most modern hosts, CDNs and caching plugins already send it automatically, so check first.
Table of Contents
Check if your site sends Vary: Accept-Encoding

- Use a free HTTP header checker such as REDbot and look for
Vary: Accept-EncodingandContent-Encoding: gziporbr. - In Chrome, open DevTools (F12) → Network, reload the page, click the first request and look under Response Headers.
- From a terminal:
curl -I -H "Accept-Encoding: gzip, br" https://example.com/
For example, this site currently returns content-encoding: br (Brotli) with vary: Accept-Encoding, set automatically by our LiteSpeed server.
Add Vary: Accept-Encoding with .htaccess (Apache and LiteSpeed)
The .htaccess file is in your site’s root folder and can be edited through your host’s File Manager or FTP. It’s a powerful file, and a mistake can take your site down, so always keep a backup first.
<IfModule mod_headers.c>
Header append Vary Accept-Encoding
</IfModule>Use Header append rather than Header set. set replaces any existing Vary values (such as Origin for CORS or User-Agent), while append adds Accept-Encoding without removing them. The IfModule wrapper means the line is simply skipped if mod_headers isn’t enabled, instead of causing a 500 error.
If you enable compression yourself with mod_deflate or mod_brotli, Apache adds the Vary header automatically for compressed responses. See the Apache mod_headers documentation for details.
Add Vary: Accept-Encoding on Nginx
gzip on;
gzip_vary on;
gzip_types text/css application/javascript application/json image/svg+xml;The gzip_vary directive adds Vary: Accept-Encoding whenever gzip is active. Reload Nginx after saving.
WordPress, caching plugins and CDNs
- LiteSpeed Cache, WP Rocket and W3 Total Cache handle compression and Vary headers on supported servers.
- Cloudflare and most CDNs compress files and manage Vary for you.
- Managed hosts usually enable gzip or Brotli at the server level. Ask support before editing .htaccess.
Compression is one of the easiest ways to increase site speed, often cutting HTML, CSS and JavaScript sizes by 70% or more.
Why the Vary header matters
- Correct caching: shared caches and CDNs store separate compressed and uncompressed copies instead of serving the wrong one.
- Speed audits: older tools like GTmetrix and PageSpeed flagged a missing Vary header. Lighthouse now focuses on whether text compression is enabled at all.
- Dynamic serving: if you serve different HTML to mobile and desktop on the same URL, Google recommends
Vary: User-Agenttoo, although a responsive design is better.
Frequently asked questions
Is Vary: Accept-Encoding still needed in 2026?
Yes, whenever your server compresses responses. Most servers and CDNs add it automatically, but it’s worth checking, especially with custom setups.
Does Vary: Accept-Encoding work with Brotli?
Yes. It covers any compression the browser announces in its Accept-Encoding request header, including gzip, Brotli (br) and Zstandard (zstd).
Should images have a Vary: Accept-Encoding header?
Not usually. JPEG, PNG, WebP and AVIF files are already compressed, so servers don’t gzip them and don’t need to vary.
Get our free weekly email: new tech guides and tools, no spam.
New and updated tech guides, a free tool worth bookmarking and one useful pick, once a week. No spam, unsubscribe anytime.
One email a week. Unsubscribe anytime. See our privacy policy.







Fantastic tips! Here’s my own idea regarding compared to that problem. I desire it can help you for one other solution approach. Open the. htaccess record and increase the under code and you also are completed. Read the particular example under. For Apache/. htaccess:
I think it’s very helpful for every parson. so try to read this article. many thanks for share this idea.
if you are using nginx or your provider is using it, this tip doesnt work
Great tips! Here’s my idea regarding to that problem. I hope it could help you for the other solution way. Open your .htaccess file and add the below code and you are done. Read the example below.
For Apache/.htaccess :
[php]# BEGIN Specify a Vary: Accept-Encoding
Header append Vary: Accept-Encoding
# END Specify a Vary: Accept-Encoding[/php]
For Nginx :
[php]gzip_vary on[/php]
For IIS :
[php]
[/php]
htaccess good joob but little know spec maybe wizard and other tools use and creat htaccess site active and protetect this..