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

What is the null coalescing operator in PHP7?

Is multiple inheritance supported in PHP?

What is an example of an object literal?

What is the difference between var, let and const in Javascript?

How to provide a default model object for relationships?

How to block IPv6 IP addresses in .htaccess

How to group a SQL statement in brackets/parenthesis

How to change the order that migrations happen?

How could you include a custom function for every single time PHP runs?

How to check if a object has a static variable defined?