2013-01-05 6 views
7

Um alle meine Webseite zu komprimieren, benutze ich diesen .htaccess Code. Es verwendet Apache deflate Modul wenn möglich, sonst wenden Sie die PHPob_gzhandler Komprimierung an.Kann ich mod_deflate & PHP dazu bringen, die Komprimierung nur für ein Verzeichnis zu überspringen?

Alles funktioniert gut, aber aus bestimmten Gründen möchte ich die Komprimierung für den Ordner ./folderWithoutCompression nicht anwenden.

Frage: Wie kann ich diese Ausnahme bei deflate Apache hinzufügen Modul definiert ist oder nicht (PHP ob_gzhandler Fall) in meinem folgenden Skript unten?

<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

Als Abhilfe, verwende ich eine benutzerdefinierte content-type für alle gegenwärtigen Dateien in meinem folderWithoutCompression Ordner.

Ich bin sicher, dass es möglich ist, ein Verzeichnis ausschließen mit <Location>, <LocationMatch>, <DirectoryMatch> oder <Directory>, aber wenn ich zu behandeln versuchen, ich habe immer einen Apache-Fehler 500

+0

Vielleicht ist es nicht möglich? – sdespont

+0

finde ich endlich die Antwort hier: https://stackoverflow.com/questions/1922934/how-to-disable-mod-deflate-in-apache2 Dank @Gumbo – sdespont

+0

ich upvoted Ihre Frage, weil es diente mir als Antwort: noch nie von diesem Filtermodul gehört, danke! – Niavlys

Antwort

0

finde ich endlich die Antwort hier:

How to disable mod_deflate in apache2?

Dank @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

Sie schreiben

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

oder Sie können in diesem Ordner eine andere .htaccess-Datei setzen, mit etwas zu deaktivieren abzulassen wie:

SetOutputFilter NONE 
Verwandte Themen