I am getting some trouble prevent mod_deflate from jumping in about this scenario:

  1. user running CodeIgniter (or other framework that re-directs to index.php)
  2. mod_deflate is active
  3. zip file is offered with a CodeIgniter controller (headers + readfile)

The truth is that Apache always picks up this content to be php and because of this something similar to the lines bellow wont work because the server assumes the ZIP file like a PHP one.

<FilesMatch "\.(xml|txt|html|php)$">
   SetOutputFilter DEFLATE
</FilesMatch>

Any applying for grants the way i might have Apache distinguish from an HTML file or perhaps a ZIP file both produced through the same index.php framework file.

Edit:
apache log

[Mon Jun 20 02:14:19 2011] [debug] 
mod_deflate.c(602): [client 192.168.0.5] 
Zlib: Compressed 50870209 to 50878224 : URL /index.php, 
referer: http://demo.dev/

Edit:
CI controller that serves the zip

header('Content-Type: application/zip');
header('Content-Transfer-Encoding: binary');
header("Content-Length: " . filesize($file_location)); 
header('Content-Disposition: attachment; filename="' . $file_title . '"'); 
readfile($file_location);

You may either:

  • make use of the deprecated AddOutputFilterByType and specify just the content types you need to do wish to filter or
  • make use of the more effective mod_filter. In FilterProvider you are able to give a rule that excludes the filter once the zip content type (application/zip) can be found in the response headers.

You are able to take advantage of mod_rewrite to alter the mime-type from the request around the Apache level:

# Serve .zip request as zip-files
RewriteRule \.zip$ - [T=application/zip,E=no-gzip:1]

Put it over the rules from the framework, however this must make DEFLATE too relied on mime-type and never file-extension while you use <FilesMatch>.

Most likely it really works well along with

AddOutputFilterByType DEFLATE text/html

rather than the <FilesMatch> Directive.

Edit: Added the L flag that ought to be utilized inshtaccess context and furthermore switched DEFLATE off through the no-gzip atmosphere variable.

Do this (as your web addresses seem to finish inssquat it could meet your needs):

<FilesMatch "\.(xml|txt|html|php)$">
   SetEnvIf Request_URI "\.zip$" no-gzip
   SetOutputFilter DEFLATE
</FilesMatch>

Even tough all solutions must have been perfectly valid inside a reasonable scenario (and were really examined just before making the question) the main reason to why I have been not able to teach Apache to deflate personal files by MIME-Type remains unknown.

I could get it act as preferred by forcing the next instructions in to the script

apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);

I actually do understand that they're a hot patch and therefore are not addressing the problem's root but to date that will need to suffice. As you will find other people who may hit exactly the same flag, the above mentioned code stays for reference in what is considered the short and dirty fix.