I want Apache to send static files gzip'ed over the wire, but also want Apache to not always gzip them over and over again. So I thought if it wouldn't be possible to deliver an .gz file if it exists. This set-up:
File structure:
static/
|
|--- style.css
|
\--- style.css.gz
And the following in an .htaccess:
mod_rewrite rule:
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
And this setting:
AddEncoding x-gzip .gz
Actually, this works insofar as the .gz file is sent instead of the .css, if the request goes to /static/style.css
. The problem is only, that the file is delivered as "application/x-gzip" and not as "text/css". Using mod_rewrite's T flag doesn't alter this. Neither does an explicit
AddType text/css .css
Has anyone an idea, how I could achieve the desired behaviour? Or is it unnecessary for some reason I didn't reckon?
EDIT: There is an additional difficulty: Sending the original file to clients without gzip support. Has anyone an idea how this could work?
A solution for sending the correct version to browsers that don't accept gzip would be something along the lines of:
Also, there is another way to change the type, namely:
HTH.
Ah, it seems I found a solution: The T flag does not work if set on the same rule, but it sure does, if you spend it a rule of its own:
Still I would like to hear others' solutions and opinions.