How to force gzip compression in Apache with .htaccess

Apache: How to force gzip compression in Apache with .htaccess

You can force Apache to compress data before sending it by adding a few lines of code to your .htaccess file.

  1. <ifModule mod_gzip.c>
  2.     mod_gzip_on Yes
  3.     mod_gzip_dechunk Yes
  4.  
  5.     mod_gzip_item_include file .(html?|txt|css|js|php)$
  6.     mod_gzip_item_include mime ^application/x-javascript.*
  7.     mod_gzip_item_include mime ^text/.*
  8.     mod_gzip_item_exclude mime ^image/.*
  9.  
  10.     mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
  11. <\/ifModule>

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to force gzip compression in Apache with .htaccess

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Apache language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to find the average value of items in a Laravel Collection?

How to Force www or non-www in htaccess

How to see all of the options for an artisan command?

How to set the timezone to UTC in .htaccess

How does PHP compare objects?

How to find the intersection (same values) from two arrays?

What is Agile software development?

How to find out which php.ini file PHP is using?

How to select what columns to return when calling ::all()

Push vs Pop vs Shift vs Unshift