如何禁用 .htaccess 文件中某些媒体文件的 Apache gzip 压缩? [英] How to disable Apache gzip compression for some media files in .htaccess file?

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

问题描述

我想对一些已经通过 .htaccess 文件在 Apache 服务器上压缩的媒体文件禁用 gzip 压缩.
原因:正如它所写的,例如jPlayer 的网站,媒体文件应禁用 gzip 编码:媒体文件已经被压缩,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 时 Content-Length 标头未正确设置 - 因此在播放带有 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_deflatemod_mimemod_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,所以我已经有了一个 RewriteRule,如下所示:

I'm using Drupal 6, so I already have a RewriteRule, which is the following:

# 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 压缩的工具,但它是全局:

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

    不使用此 RewriteRule 时 mp3 文件的响应标头:http://pastebin.com/AkUZ6m5Y
    使用此 RewriteRule 时 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

    推荐答案

    我不得不禁用 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
    

    并且服务器禁用了对 odp 文件的压缩测试前请务必清除浏览器缓存

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

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

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