2013-01-05 9 views
7

すべてのWebページを圧縮するには、この.htaccessコードを使用します。可能であればApache deflateモジュールを使用し、それ以外の場合はPHPob_gzhandler圧縮を適用します。mod_deflate&PHPにあるディレクトリの圧縮をスキップするよう伝えることはできますか?

すべてうまくいきますが、具体的な理由から、私はフォルダ./folderWithoutCompressionに圧縮を適用したくありません。

質問:以下のスクリプトでApache deflateモジュールが定義されているかどうか(PHP ob_gzhandlerの場合)この例外を追加するにはどうすればよいですか?回避策として

<IfModule mod_deflate.c> 
    # force deflate for mangled headers 
    # developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ 
    <IfModule mod_setenvif.c> 
    <IfModule mod_headers.c> 
     SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding 
     RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding 
    </IfModule> 
    </IfModule> 

    # HTML, TXT, CSS, JavaScript, JSON, XML, HTC: 
    <IfModule filter_module> 
    FilterDeclare COMPRESS 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf 
    FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype 
    FilterChain  COMPRESS 
    FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no 
    </IfModule> 

    <IfModule !mod_filter.c> 
    # Legacy versions of Apache 
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json 
    AddOutputFilterByType DEFLATE application/javascript 
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component 
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml 
    AddOutputFilterByType DEFLATE application/atom+xml 
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject 
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype 
    </IfModule> 
</IfModule> 

<IfModule !mod_deflate.c> 
    #Apache deflate module is not defined, active the page compression through PHP ob_gzhandler 
    php_flag output_buffering On 
    php_value output_handler ob_gzhandler 
</IfModule> 

EDIT

、私は私のfolderWithoutCompressionフォルダに存在するすべてのファイルのカスタムcontent-typeを使用しています。

あなたが書くことができ、私は<Location><LocationMatch><DirectoryMatch>または<Directory>を使用して、いくつかのディレクトリを除外することが可能であることを確信しているが、私が対処しようとしたとき、私は常にApacheのエラー500

+0

@Gumboおかげで多分それができないのですか? – sdespont

+0

私は最終的にここで答えを見つける: https://stackoverflow.com/questions/1922934/how-to-disable-mod-deflate-in-apache2私はので、あなたの質問にupvotedおかげ@Gumbo – sdespont

+0

それは私のための答えとして役立った:前に、このフィルタモジュールを聞いたことはありません、ありがとう! – Niavlys

答えて

0

私は最終的にここで答えを見つける:

How to disable mod_deflate in apache2?

# for URL paths that begin with "/foo/bar/" 
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1 

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

を得た

SetEnvIf Request_URI ^/path/to/folder/ no-gzip=1 

か、のようなものでデフレート無効にそのフォルダ内の別の.htaccessファイルを置くことができます。

SetOutputFilter NONE