You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Joost Schuttelaar <jo...@joostschuttelaar.nl> on 2010/06/01 18:12:43 UTC

[users@httpd] htaccess and httpd.conf precedence (mod_deflate)

Hi everybody,

I'm running a Apache installation using a standard DirectAdmin setup, but I'm having problems with handling of gzipped output.

One of my PHP scripts outputs a .ZIP file (with appropriate headers). By default, the output of this script gets gzipped by mod_deflate. Of course there is no need to gzip a zip file, but decent browsers have no problem handling this. Internet Explorer mangles the file though, unless you set a non standard content type.

So, in order to fix this and disable gzip for this script, I've set up a line in my .htaccess file:

SetEnvIf Request_URI download_file\.php$ no-gzip dont-vary

When I test this using wget (wget --header="Accept-Encoding: gzip,deflate") this works fine. Output from this script does not get gzipped. However, if I add the IE user agent header (User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;.....) the content still gets gzipped.

Strangely, when I replace the above line with 'SetEnv no-gzip', the content does not get gzipped even though I send the IE user agent header. I've traced this back to the stock httpd-deflate.conf which is included in my httpd.conf. It contains the following line:

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

When I comment this line out, things work as expected... does, for some reason, a BrowserMatch reffered from httpd.conf have precedence over what's in a .htaccess file? Any suggestions? I could change my httpd.conf, but when the site for instance gets moved to a different server this problem might rear it's ugly head again...

Thanks!

-- 

Joost Schuttelaar
The Hague, NL


---------------------------------------------------------------------
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@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] htaccess and httpd.conf precedence (mod_deflate)

Posted by Joost Schuttelaar <jo...@joostschuttelaar.nl>.
Hi Eric,

> two pieces of trivia that might fill in some blanks:
> 
> 1) SetEnv runs much later than SetEnvIf/BrowserMatch no matter what
> context you place it in
> 
> 2)  somewhat counterintuitively, <Location has precedence over
> <Directory  -- perhaps you could wrap the canned deflate stuff in a
> <Directory> entry at a higher then your htaccess so the htaccess is
> processed second?

Thanks a lot! Actually these two pieces of trivia and http://httpd.apache.org/docs/2.0/sections.html#mergin filled in all the blanks. I've added a conditional override in the httpd-deflate.conf:

SetEnvIf override-gzip-in-httpd-deflate-conf 1 no-gzip dont-vary

And used that in my .htaccess file:

SetEnvIf Request_URI download_file\.php$ no-gzip dont-vary override-gzip-in-httpd-deflate-conf

Not an ideal solution, since it might not survive a site migration but at least the fix is kinda explicit...

-- 

Joost Schuttelaar
The Hague, NL


---------------------------------------------------------------------
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@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] htaccess and httpd.conf precedence (mod_deflate)

Posted by Eric Covener <co...@gmail.com>.
On Tue, Jun 1, 2010 at 12:12 PM, Joost Schuttelaar
<jo...@joostschuttelaar.nl> wrote:
> Hi everybody,
>
> I'm running a Apache installation using a standard DirectAdmin setup, but I'm having problems with handling of gzipped output.
>
> One of my PHP scripts outputs a .ZIP file (with appropriate headers). By default, the output of this script gets gzipped by mod_deflate. Of course there is no need to gzip a zip file, but decent browsers have no problem handling this. Internet Explorer mangles the file though, unless you set a non standard content type.
>
> So, in order to fix this and disable gzip for this script, I've set up a line in my .htaccess file:
>
> SetEnvIf Request_URI download_file\.php$ no-gzip dont-vary
>
> When I test this using wget (wget --header="Accept-Encoding: gzip,deflate") this works fine. Output from this script does not get gzipped. However, if I add the IE user agent header (User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;.....) the content still gets gzipped.
>
> Strangely, when I replace the above line with 'SetEnv no-gzip', the content does not get gzipped even though I send the IE user agent header. I've traced this back to the stock httpd-deflate.conf which is included in my httpd.conf. It contains the following line:
>
> BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
>
> When I comment this line out, things work as expected... does, for some reason, a BrowserMatch reffered from httpd.conf have precedence over what's in a .htaccess file? Any suggestions? I could change my httpd.conf, but when the site for instance gets moved to a different server this problem might rear it's ugly head again...


two pieces of trivia that might fill in some blanks:

1) SetEnv runs much later than SetEnvIf/BrowserMatch no matter what
context you place it in

2)  somewhat counterintuitively, <Location has precedence over
<Directory  -- perhaps you could wrap the canned deflate stuff in a
<Directory> entry at a higher then your htaccess so the htaccess is
processed second?


-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org