How to disable Apache gzip compression for some media files in .htaccess file?

后端 未结 6 645
旧巷少年郎
旧巷少年郎 2020-12-09 10:02

I would like to disable gzip compression for some media files which are already compressed on an Apache server via the .htaccess file.
Reas

相关标签:
6条回答
  • 2020-12-09 10:35

    this seems outdated : https://www.varnish-cache.org/docs/3.0/tutorial/compression.html#gzip-and-esi

    GZIP and ESI

    If you are using Edge Side Includes you'll be happy to note that ESI and GZIP work together really well. Varnish will magically decompress the content to do the ESI-processing, then recompress it for efficient storage and delivery.

    0 讨论(0)
  • 2020-12-09 10:38

    Are you not going about this the wrong way round by using the directive SetOutputFilter DEFLATE and then trying to disable this for stream which already include some form of compresstion? Isn't it a lot easier not to use this directive and then compress the stream that are compressible. E.g.

    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript application/ecmascript application/rss+xml
    </IfModule>
    

    And possibly adding a Vary header:

    <IfModule mod_headers.c>
        <FilesMatch "\.(js|css|xml|html)$">
            Header append Vary Accept-Encoding
        </FilesMatch>
    </IfModule>
    

    OK this may miss the odd type that you've not thought of, but it will achieve 99+% of your compression potential.

    0 讨论(0)
  • 2020-12-09 10:43

    To disable gzip compression on just Adobe Flash Player files (SWFs) on my Apache server, I added this to my .htaccess file:

    <IfModule mod_headers.c>
        <FilesMatch "\.swf$">
            RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
        </FilesMatch>
    </IfModule>
    

    If you wanted to, you could disable gzip compression for other file types as well:

    <IfModule mod_headers.c>
        <FilesMatch "\.(js|css|swf)$">
            RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
        </FilesMatch>
    </IfModule>
    
    0 讨论(0)
  • 2020-12-09 10:45

    I had to disable compression for odp files for use by external plugin Just added the following rule in .htaccess file

    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI \.odp$ no-gzip dont-vary
    

    And the server disabled compression for odp files Make sure to clear the browser cache before testing

    0 讨论(0)
  • 2020-12-09 10:48

    I think you are not using compression in your media. Did you check that you are in fact deflating files? The module can be loaded in memory, but that doesn't mean it's compressing files. If your .htaccess only has rewrite rules chances are you are not compressing any kind of content.

    0 讨论(0)
  • 2020-12-09 10:49

    I know this thread is old, but I have gone through the same path.

    Two things I have done.

    1. I enabled .htaccess and disabled gzip for a folder completely.

      <Files "*.gz.asc">
           RemoveEncoding .gz
       </Files>
      
    2. put a reqwrite rule to disable

      RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1] 
      

    Both of these worked for me I would suggest going to Apache documentation first before searching on forums.

    for more information please go to Apache website.

    https://httpd.apache.org/docs/2.4/mod/mod_deflate.html https://httpd.apache.org/docs/2.4/mod/mod_mime.html#addtype

    0 讨论(0)
提交回复
热议问题