Forum Moderators: phranque
That's just one way to do it. You can get fancy and do the first step using a cron job, or add another function to invoke gzip if a gzipped version of the file does not exist or if it is older than the If-Modified-Since request header sent by the client.
This is just one of many ways to do it -- There are many possibilities.
Jim
RewriteEngine on
RewriteLog "logs/modrewrite.log"
RewriteLogLevel 9
# If client accepts compressed files
RewriteCond %{HTTP:Accept-Encoding} gzip
# and if compressed file exists
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f
# send .html.gz instead of .html
RewriteRule ^(.+)\.(js¦xml¦css¦html)$ $1.$2.gz [L]
the file abcd.xml can be rewrite to abcd.xml.gz£¬but it is not used yet
while I access http://www.example.com/abcd.xml using firefox,
it popup a dialog to ask me save or open a file?!
I checked the response from the server(httpd2.x)
HTTP/1.1 200 OK
Date: Fri, 14 Dec 2007 01:57:25 GMT
Server: Apache/2.2.2 (Fedora)
Vary: Accept-Encoding
Last-Modified: Thu, 13 Dec 2007 09:41:42 GMT
ETag: "4d08b0-fe-c0dbc180"
Accept-Ranges: bytes
Content-Length: 254
Cache-Control: max-age=1151056
Expires: Thu, 27 Dec 2007 09:41:42 GMT
Content-Type: application/x-gzip
I think maybe it missed a HTTP header "Content-Encoding: gzip"?
[edited by: jdMorgan at 5:17 am (utc) on Jan. 9, 2008]
[edit reason] example.com [/edit]
RewriteEngine on
RewriteLog "logs/modrewrite.log"
RewriteLogLevel 9
# If client accepts compressed files
RewriteCond %{HTTP:Accept-Encoding} gzip
# and if compressed file exists
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f
# send .html.gz instead of .html
RewriteRule ^(.+)\.(html¦xml¦css)$ $1.$2.gz [T=text/$2,E=GZIP:gzip,L]
Header set Content-Encoding gzip env=GZIP
[edited by: jdMorgan at 5:16 am (utc) on Jan. 9, 2008]
[edit reason] tidying-up [/edit]
RewriteRule ^(.+)\.(html¦xml¦css)$ $1.$2.gz [T=text/$2,E=GZIP:gzip,L]
[edited by: jdMorgan at 5:17 am (utc) on Jan. 9, 2008]
[edit reason] Tidying-up. [/edit]