Preventing dynamically-served files from being gzipped (with clean URLs)

Discussion in 'Server Operation' started by cbj4074, May 23, 2012.

  1. cbj4074

    cbj4074 Member


    I (and others) have come to realize that IE 6/7/8 will double-compress any already-compressed file -- and fail to double-de-compress it -- when gzip compression is enabled for, e.g., a ZIP file download.

    To work around this limitation, I need to have some means by which to exclude certain URLs from compression.

    On its face, this seems simple enough, but this particular application requires the use of so-called "clean URLs". As such, Apache's SetEnvIf module seems not to be able to access the "clean URL"; it always sees "/index.php" for the "Request_URI".

    I have this mod_rewrite rule:

    # Rewrite URLs of the form 'index.php?q=x':
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [QSA,L]
    I was hoping to be able to force no-gzip with something like this:

    SetEnvIfNoCase Request_URI (.*)(/|download/.*)$ no-gzip dont-vary
    The idea is that anything that is in a "download" directory does not receive gzip compression (which is enabled site-wide).

    The problem is that the SetEnvIf directive is never satisfied because, as stated above, Request_URI always equals the "true" URI, as it exists before the clean URL" rewriting is performed: "/index.php".

    I considered using mod_rewrite to modify the CGI environment variables, but I don't like that solution because a) it very likely wouldn't work when PHP is running under Mod-PHP (as opposed to Fast-CGI), it wouldn't work if SuPHP is in use, and it may not even be possible to modify the "no-gzip" environment variable; the Apache docs state: "It is not possible to override or change the standard CGI variables using the environment manipulation directives."

    Does anyone have any other ideas?

    EDIT to add: This kind of thing doesn't work, for the reasons outlined above:

    # Don't compress images (or other files that are already compressed)
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png|zip|7z|rar|sit?x|mp3|flac|ogg|pdf)$ no-gzip dont-vary
    Last edited: May 23, 2012
  2. falko

    falko Super Moderator ISPConfig Developer

Share This Page