poor man's mod_deflate (mod_rewrite recipe)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,

We have been playing around with mod_deflate and caching
the other day to solve an urgent performance problem, where
mod_deflate was not an option.

We got some sort of poor man's mod_deflate out of it.

It works on static files only and it means you have to
gzip the static files in the filesystem in order to make
it work. But afterwards you'll get a really fast server.

I think it is worth posting it here, as it is a good example for
mod_rewrite use.

<VirtualHost *:80>
    RewriteEngine On

    RewriteCond "%{HTTP:Accept-Encoding}" "gzip.*deflate|deflate.*gzip" 
    RewriteCond /data/custom-apaches/apache-2.0.61/htdocs/%{REQUEST_FILENAME}.gz -f
    RewriteRule /(.*) /$1.gz [last,env=deflated:1]

    Header set Vary             "Accept-Encoding" env=deflated
    Header set Content-Encoding "gzip"            env=deflated

</Virtualhost>

Adjust your paths accordingly.

Explanation:
On the first RewriteCond line, we check wether the browser accepts
deflated content (Accept-Encoding Header).
On the next line, we check wether there is a gzip file to the non-zipped
filename, that the user requested. If there is one, then the RewriteRule
comes into play. Here we rewrite the filename to filename.gz and set
the environment variable "deflated" to 1.

The effect of this construct is, that unless the browser asks for
zipped content and unless there is a zipped file in the filesystem,
the server will behave as usual. However, if these conditions are met, it
sends the zipped file instead of the standard one.

During the response phase, we add two headers to the response if the
environment variable "deflated" is set.

You may have to tweak this to work on full paths and not only on
filenames. You may also want to write a cronjob to zip your files
from time to time. And maybe you just go for the real thing and
install mod_deflate. Otherwise, I enjoyed writing this hack.

regards,

Christian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux