I use precomposed gzipped CSS and JS files, so that server doesn't do this on the fly.
So in the same folder I have file.css (gzipped version), file.nozip.css (nogzipped version). Then depending whether browser accepts gzipped files or not, send proper version.
So I have the following in .htaccess:
RewriteEngine On
RewriteRule ^(.*)\.[0-9]+\.css$ $1.css [L]
#redirect Konqueror and "old browsers"
RewriteCond %{REQUEST_FILENAME} !\.nogzip\.css$
RewriteCond %{HTTP:Accept-encoding} !gzip [OR]
RewriteCond %{HTTP_USER_AGENT} Konqueror
RewriteRule ^(.*)\.css$ $1.nogzip.css [L]
<IfModule mod_headers.c>
Header set Vary User-Agent
#set Content-Encoding for all css files
<FilesMatch .*\.css$>
Header set Content-Encoding: gzip
Header set Cache-control: private
</FilesMatch>
#drop Content-Encoding in case we send not gzipped file
<FilesMatch .*\.nogzip\.css$>
Header unset Content-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A36000000
</IfModule>
This approach I used many times before both as on Windows as well on Linux servers. Worked fine always.
However, recently while developing another site I face issue with the browser not recognizing the gzipped file as gzipped.
On localhost is working, here is the response header:
Accept-Ranges:bytes
Cache-control:private
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:39115
Content-Type:text/css
Date:Wed, 17 Jun 2015 11:27:28 GMT
ETag:"98cb-517998d9e690c"
Keep-Alive:timeout=5, max=100
Last-Modified:Wed, 03 Jun 2015 09:19:16 GMT
Server:Apache/2.4.12 (Win64) OpenSSL/1.0.1m PHP/5.6.9
Vary:User-Agent
X-Distributed-by:AHC
Here is the header received from the production server (not working - css file displayed as zipped in the browser):
Accept-Ranges:bytes
Cache-control:private
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:39099
Content-Type:text/css
Date:Wed, 17 Jun 2015 11:30:08 GMT
ETag:"98cb-517998d8fcd00-gzip"
Keep-Alive:timeout=5, max=99
Last-Modified:Wed, 03 Jun 2015 09:19:16 GMT
Server:Apache/2.4.10 (Debian)
Vary:User-Agent
The only difference is "X-Distributed-by:AHC", but this hardly be the reason for problem.
Any ideas what else to check?
In case 2, it strongly implies mod_deflate compressed it on the fly due to the etag:
Maybe it would be best to set no-gzip for e.g. the konqueror case?