Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent mod_deflate on zip file served by PHP

I'm having some trouble prevent mod_deflate from jumping in on this scenario:

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

The thing is that Apache always detects the content as being php and therefor something like the lines bellow wont work as the server assumes the ZIP file as being a PHP one.

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

Any ideas on how I can have Apache distinguish from an HTML file or a ZIP file both generated by 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);
like image 984
Frankie Avatar asked Jun 20 '11 00:06

Frankie


1 Answers

Even tough all answers should have been perfectly valid in a reasonable scenario (and were actually tested prior to making the question) the reason to why I've been unable to instruct Apache to deflate a file by MIME-Type remains unknown.

I was able to have it work as desired by forcing the following instructions into the script

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

I do understand that this is a hot patch and is not addressing the problem's root but so far that will have to suffice. As there are others who may hit the same flag, the above code stays here for reference in what is a dirty fix.

like image 191
Frankie Avatar answered Sep 19 '22 12:09

Frankie