如何禁用Apache的gzip的COM pression在.htaccess文件的一些媒体文件? [英] How to disable Apache gzip compression for some media files in .htaccess file?

查看:226
本文介绍了如何禁用Apache的gzip的COM pression在.htaccess文件的一些媒体文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用GZIP COM pression对于一些媒体文件,这些文件已融为一体pressed通过Apache服务器上的的.htaccess 文件。
原因:因为它写在如 jPlayer的网站,gzip编码应为媒体文件被禁用:媒体文件已经融为一体pressed和GZIP只会浪费CPU的服务器上。如果你GZIP媒体的Adobe Flash插件就会遇到问题。

I would like to disable gzip compression for some media files which are already compressed on an Apache server via the .htaccess file.
Reason: as it's written on e.g. jPlayer's site, gzip encoding should be disabled for media files: "Media files are already compressed and the GZIP will just waste CPU on your server. The Adobe Flash Plugin will experience issues if you GZIP the media."

我目前遇到的问题是内容长度头时,GZIP启用设置得不正确 - 所以玩了的SoundManager2 播放器,轨道的长度进度条不正常进行,(也许这就是他们讲述了在jPlayer的网站上的问题)。

I'm currently having the problem that Content-Length header is not properly set when gzip is enabled - so when playing some mp3-files with a SoundManager2 player, the track's length progress bar doesn't work appropriately (so maybe that's the problem they told about on jPlayer's site).

我可以测试是否一个内容提供服务gzip压缩这里
我确实有 mod_deflate模块 mod_mime 的mod_rewrite 模块上启用服务器。
据phpinfo()函数,这里是所有已加载模块的列表:

I can test if a content is served gzipped here.
I do have mod_deflate, mod_mime and mod_rewrite modules enabled on the server.
According to a phpinfo(), here is a list of all the loaded modules:

core mod_log_config mod_logio itk http_core mod_so mod_alias mod_auth_basic mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dav mod_dav_svn mod_authz_svn mod_deflate mod_dir mod_env mod_mime mod_negotiation mod_php5 mod_reqtimeout mod_rewrite mod_setenvif mod_ssl mod_status

我使用的Drupal 6,所以我已经有一个重写规则,它是这样的:

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


我已经尝试了这些禁用GZIP,但他们没有工作(有6个不同的尝试 - !也许有些人会必须在Apache的httpd.conf全局设置? !):


I've already tried these to disable gzip, but they didn't work (there are 6 different tries! - maybe some of them would have to be set globally in Apache's httpd.conf?!):

# http://www.cyberciti.biz/tips/speed-up-apache-20-web-access-or-downloads-with-mod_deflate.html
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary    

  • ## Step 2. here: http://www.mydigitallife.info/how-to-enable-mod_deflate-gzip-compression-on-cpanel-web-hosts/
    <IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    
    RemoveOutputFilter mp3
    # Don’t compress already-compressed files
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:avi|mov|mp3|mp4|rm|flv|swf|mp?g)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
    </IfModule>
    

  • RemoveOutputFilter mp3
    

  • # for files that end with ".mp3"
    <FilesMatch \.mp3$>
    SetEnv no-gzip 1
    </FilesMatch>
    

  • RewriteRule \.mp3$ - [NS,E=no-gzip:1,E=dont-vary:1]
    

  • RewriteRule ^((.*)\.mp3)$ $1.mp3 [NS,E=no-gzip:1,E=dont-vary:1]   
    

  • 唯一一个可以正常工作,并禁用GZIP COM pression,但它的全球的:

    The only one which works correctly, and disables gzip compression, BUT it is global:

    RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
    

    对于MP3文件的响应头时,不使用这个重写规则: http://pastebin.com/AkUZ6m5Y
    对于MP3文件的响应头使用此重写规则时: http://pastebin.com/b8j3NF6D

    Response headers for an mp3-file when NOT using this RewriteRule: http://pastebin.com/AkUZ6m5Y
    Response headers for an mp3-file when using this RewriteRule: http://pastebin.com/b8j3NF6D

    推荐答案

    我不得不禁用COM pression的ODP文件外部插件使用 只需添加以下规则在.htaccess文件

    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
    

    和服务器禁用COM pression的ODP文件 确保清除浏览器缓存测试之前

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

    这篇关于如何禁用Apache的gzip的COM pression在.htaccess文件的一些媒体文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆