Performance and monitoring

Disable Gzip and Brotli compression from .htaccess

Reviewed on 3 min read Gzip compression

Our servers automatically compress HTML, CSS and JavaScript with Gzip or Brotli. If an application or script does not work properly with the compressed response (for example, because it already compresses the output itself, or because it streams data), you can disable compression from .htaccess. The change takes effect immediately, without restarting anything.

Disable it

Add this at the beginning of the .htaccess file:

SetEnv no-gzip 1
SetEnv no-brotli 1

The first line disables Gzip and the second Brotli. Add both: if you only disable Gzip, modern browsers will keep receiving Brotli.

If you prefer to use rewrite rules, the alternative for Gzip is:

RewriteEngine On
RewriteRule . - [E=no-gzip:1]

SetEnv is the option LiteSpeed recommends, because other RewriteRule rules in the file (WordPress's, for example) can stop the rewrite rule from being applied.

Choose where to put it

The .htaccess file affects its own directory and every directory below it:

  • In public_html/.htaccess, compression is disabled for the main domain and for any addon domains and subdomains whose folders are inside public_html.
  • To limit it to a single website or folder (for example, an API's), put it in that folder's .htaccess.

Check that it has been disabled

  1. Open the website in a private window, press F12 and go to the Network tab.
  2. Reload with Ctrl + F5 (or Cmd + Shift + R on a Mac) so you do not see the browser's cached copy.
  3. Click the request for the document or file you are interested in and look at the response headers: Content-Encoding: gzip or Content-Encoding: br should no longer appear.

You can also check it from the terminal with:

curl -s -o /dev/null -D - -H "Accept-Encoding: gzip, br" https://tudominio.com/ | grep -i content-encoding

If it returns nothing, the response is uncompressed.

If it still appears compressed, the cause may be:

  • A CDN such as Cloudflare: it compresses what it delivers to the visitor itself. Disable it on the CDN or check directly against the server.
  • The application itself: if the PHP code uses ob_gzhandler or zlib.output_compression, that compression is not controlled by the server. Remove it from the code or set zlib.output_compression = Off in the website's PHP configuration.

Turn it back on

Delete the lines you added and save. Compression works again immediately. Keeping it on greatly reduces the size of your pages, so only disable it where you need to.

You may also find useful

Something wrong or out of date? Tell us and we will review it.