Entries Tagged as 'apache2.x'

pre-compress static content in apache2.x by using mod_header + mod_rewrite

以下内容放到httpd.conf文件的合适位置

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}%{SCRIPT_FILENAME}.gz -f
# send .html.gz instead of .html
RewriteRule ^(.+)\.(html|xml|css)$ $1.$2.gz [T=text/$2,E=GZIP:gzip,L]
# notice: the line above is used in httpd 2.2.x, not in the httpd2.0.x
# RewriteRule ^(.+\.xml)$ $1.gz [T=text/xml,E=GZIP:gzip,L]
# RewriteRule ^(.+\.css)$ $1.gz [T=text/css,E=GZIP:gzip,L]
# RewriteRule ^(.+\.js)$ $1.gz [T=application/x-javascript,E=GZIP:gzip,L]
Header set Content-Encoding gzip env=GZIP