Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So there's a file in Wordpress, wp-content/blogs.php, that serves files uploaded through Wordpress. There's a rewrite rule in the WP .htaccess that rewrites URLs of the format to URLs of the format

RewriteRule ^(./)?files/(.) wp-content/blogs.php?file=$2 [L]

So here's the problem: we have gzip turned on for php files. I need to turn it off based on the query parameter "file", on blogs.php. (Not just because you're not supposed to gzip binaries, but because gzipping .mp3 creates severe problems for the Quicktime plugin in Firefox on both PC and Mac.)

But the following SetEnvIf isn't applied to any files served through blogs.php-- the Request_URI always ends in .php

SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary

The following fixes the problem by turning off gzip on all files served through blogs.php:

<Location /michael/blah/wp-content/blogs.php>        
     SetEnv no-gzip

But it's not a good solution, because I want non-binary files served through blogs.php to be gzipped. So what I really want is a way to get the original URI, not the rewritten URI, because the original URI does end in .mp3. Or, I need to access the query parameter at the end of the rewritten URI (file=filename.mp3).

For instance, something like this would work, if it existed, which it doesn't:

SetEnvIfNoCase Original_Request_URI \.mp3$ no-gzip dont-vary

It looks like there's a variable THE_REQUEST that would work in a RewriteRule, but it doesn't seem available to SetEnv.

Any ideas? Thanks! And let me know if I'm violating any rules, it's my first time posting here.

share|improve this question

You can manipulate the environment from mod_rewrite, including turning off gzip:

RewriteCond %{QUERY_STRING} file=(.*)\.mp3$
RewriteRule ^(./)?files/(.) wp-content/blogs.php?file=$2 [L,E=no-gzip:1]

The first RewriteCond may not be necessary, but the last rule (the E flag) should do the trick in your setup regardless.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.