In apache htdocs, I want to have only compressed files (gzip file) and based on accepted encoding types, if gzip encoding is enabled, I want apache to serve a compressed file, and if gzip encoding is not supported, then I want apache to work. unpacking gzip files.
I do not want to store uncompressed files and use deflate for compression upon access, as this will be inefficient, and by default all clients support gzip encoding.
Having both compressed and uncompressed files (example.js and example.jsgz both in the htdocs directory), I was able to do this work using RedirectCond using the accepted encoding of the request and RedirectRules. But for this we need two files for storage (compressed and regular). The following is the configuration used with forwarding rules.
<Directory /var/www/app>
AddEncoding gzip .jsgz .cssgz .htmlgz
AddType text/javascript .jsgz
AddType text/css .cssgz
AddType text/html .htmlgz
SetEnv force-no-vary
Header set Cache-Control "private"
RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}gz -f
RewriteRule ^(.+)\.(html|css|js)$ $1.$2gz [L]
</Directory>
I do not want to do as described above, since I have to store both versions of each file.
For instance:
Application directory contents inside htdocs
ls app/
example.jsgz
Apache server configuration for application directory
In this case, with the MultiView parameter, I can example.jsgz server when the example.js request file as an example .js is missing. And the configuration on my apache side is as follows:
<Directory /var/www/htdocs/app>
AddEncoding gzip .jsgz .cssgz .htmlgz
AddType text/javascript .jsgz
AddType text/css .cssgz
AddType text/html .htmlgz
Options +Multiviews
SetEnv force-no-vary
Header set Cache-Control "private"
</Directory>
Case 1:
, gzip. url - example.js, example.jsgz. example.jsgz , gzip js.
Request URL:http://A.B.C.D/app/example.js
Request Method:GET
Request HTTP headers:
Accept-Encoding:gzip,deflate,sdch
Response Headers:
Content-Encoding:gzip
2:
, gzip . url - example.js, example.jsgz. , apache example.jsgz, , gzip .
Request URL:http://A.B.C.D/app/example.js
Request Method:GET
Request HTTP headers:
Response Headers:
Content-Encoding:gzip
2, gzip, htdocs?
. Multiviews. , (javascript, css, html) (gzip encoded).