2013-01-05 8 views
7

Aby skompresować całą moją stronę, używam tego kodu .htaccess. Jeśli to możliwe, korzysta z modułu Apache deflate, w przeciwnym razie zastosuj kompresję PHPob_gzhandler.Czy mogę powiedzieć mod_deflate i PHP, aby pominąć kompresję tylko w jednym katalogu?

Wszystko działa poprawnie, ale z konkretnego powodu nie chcę stosować kompresji dla folderu ./folderWithoutCompression.

Pytanie: Jak mogę dodać ten wyjątek w przypadku Apache module deflate jest zdefiniowana lub nie (PHP ob_gzhandler przypadek) w następującym poniżej mojego skryptu?

<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

Jako obejście, używam niestandardowej content-type dla wszystkich plików znajdujących się w folderze Moje folderWithoutCompression.

Jestem pewien, że można wykluczyć wybrane katalogi korzystając <Location>, <LocationMatch>, <DirectoryMatch> lub <Directory>, ale gdy próbuję do czynienia, zawsze masz błąd Apache 500

+0

Może to nie jest możliwe? – sdespont

+0

I wreszcie znaleźć odpowiedź tutaj: https://stackoverflow.com/questions/1922934/how-to-disable-mod-deflate-in-apache2 Dzięki @Gumbo – sdespont

+0

I upvoted swoje pytanie, ponieważ Odpowiedź ta była dla mnie odpowiedzią: nigdy nie słyszałem o tym module filtrującym, dzięki! – Niavlys

Odpowiedz

0

I wreszcie znaleźć odpowiedź tutaj:

How to disable mod_deflate in apache2?

Thanks @Gumbo

# 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

Możesz napisać

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

lub można umieścić inny plik .htaccess wewnątrz tego folderu wyłączenie spuścić powietrze z czymś takim:

SetOutputFilter NONE 
Powiązane problemy