GZIP aktivieren bei 1und1 über .hataccess

  • Hallo!

    Hallo ich versuche gerade gzip Kompression einzuschalten benutze einen 1und1 Server. Habe die GZIP Kompression im Shop aktiviert.
    gtmetrix.com meldet mir gzip aktivieren.

    ich verwende folgende .htaccess

    Apache Configuration
    # ----------------------------------------------------------------------# UTF-8 encoding# ----------------------------------------------------------------------# Use UTF-8 encoding for anything served text/plain or text/htmlAddDefaultCharset utf-8# Force UTF-8 for a number of file formatsAddCharset utf-8 .html .css .js .xml .json .rss .atom .php# Wenn Sie 1und1 benutzen, setzen Sie die nächsten beiden Zeilen aktiv (Einschalten PHP5.4) Bei 1und1 sollte weiter unten der Punkt RewriteBase / auch auskommentiert werdenAddHandler x-mapp-php6 .php3 .php4 .php .phtml# ----------------------------------------------------------------------# Expires headers (for better cache control)# ----------------------------------------------------------------------#zlib.output_compression = On<IfModule mod_deflate.c>  # Compress HTML, CSS, JavaScript, Text, XML and fonts  AddOutputFilterByType DEFLATE application/javascript  AddOutputFilterByType DEFLATE application/rss+xml  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject  AddOutputFilterByType DEFLATE application/x-font  AddOutputFilterByType DEFLATE application/x-font-opentype  AddOutputFilterByType DEFLATE application/x-font-otf  AddOutputFilterByType DEFLATE application/x-font-truetype  AddOutputFilterByType DEFLATE application/x-font-ttf  AddOutputFilterByType DEFLATE application/x-javascript  AddOutputFilterByType DEFLATE application/xhtml+xml  AddOutputFilterByType DEFLATE application/xml  AddOutputFilterByType DEFLATE font/opentype  AddOutputFilterByType DEFLATE font/otf  AddOutputFilterByType DEFLATE font/ttf  AddOutputFilterByType DEFLATE image/svg+xml  AddOutputFilterByType DEFLATE image/x-icon  AddOutputFilterByType DEFLATE text/css  AddOutputFilterByType DEFLATE text/html  AddOutputFilterByType DEFLATE text/javascript  AddOutputFilterByType DEFLATE text/plain  AddOutputFilterByType DEFLATE text/xml  # Remove browser bugs (only needed for really old browsers)  BrowserMatch ^Mozilla/4 gzip-only-text/html  BrowserMatch ^Mozilla/4\.0[678] no-gzip  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html  Header append Vary User-Agent</IfModule><IfModule mod_expires.c>  ExpiresActive on# Perhaps better to whitelist expires rules? Perhaps.  ExpiresDefault                          "access plus 1 month"  ExpiresByType text/cache-manifest       "access plus 0 seconds"  ExpiresByType text/html                 "access plus 0 seconds"  ExpiresByType text/xml                  "access plus 0 seconds"  ExpiresByType application/xml           "access plus 0 seconds"  ExpiresByType application/json          "access plus 0 seconds"  ExpiresByType application/rss+xml       "access plus 1 hour"  ExpiresByType application/atom+xml      "access plus 1 hour"  ExpiresByType image/x-icon              "access plus 1 week"   ExpiresByType image/gif                 "access plus 1 month"  ExpiresByType image/png                 "access plus 1 month"  ExpiresByType image/jpg                 "access plus 1 month"  ExpiresByType image/jpeg                "access plus 1 month"  ExpiresByType video/ogg                 "access plus 1 month"  ExpiresByType audio/ogg                 "access plus 1 month"  ExpiresByType video/mp4                 "access plus 1 month"  ExpiresByType video/webm                "access plus 1 month"  ExpiresByType text/x-component          "access plus 1 month"  ExpiresByType font/truetype             "access plus 1 month"  ExpiresByType font/opentype             "access plus 1 month"  ExpiresByType application/x-font-woff   "access plus 1 month"  ExpiresByType image/svg+xml             "access plus 1 month"  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"  ExpiresByType text/css                  "access plus 1 year"  ExpiresByType application/javascript    "access plus 1 year"  ExpiresByType application/x-javascript  "access plus 1 year"    <IfModule mod_headers.c>    Header append Cache-Control "public"  </IfModule></IfModule># BEGIN Cache-Control Headers<ifmodule mod_headers.c>	<filesmatch "\\.(ico|jpe?g|png|gif|swf)$">		Header set Cache-Control "max-age=31536000, public"	</filesmatch>	<filesmatch "\\.(css)$">		Header set Cache-Control "max-age=31536000, public"	</filesmatch>	<filesmatch "\\.(js)$">		Header set Cache-Control "max-age=31536000, public"	</filesmatch>	<filesmatch "\\.(jgz)$">		Header set Cache-Control "max-age=31536000, public"	</filesmatch>	<filesmatch "\\.(ico)$">		Header set Cache-Control "max-age=31536000, public"	</filesmatch>		<filesmatch "\\.(html)$">		Header set Cache-Control "max-age=31536000, public"	</filesmatch>	Header unset ETag	<filesmatch "\.(js|css|xml|gz|jgz)$">		Header append Vary: Accept-Encoding	</filesmatch></ifmodule><ifmodule mod_deflate.c><filesmatch "\\.(js|css|html|htm|php|xml)$">SetOutputFilter DEFLATE</filesmatch></ifmodule># ----------------------------------------------------------------------# Gzip compression# ----------------------------------------------------------------------<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></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># ----------------------------------------------------------------------# ETag removal# ----------------------------------------------------------------------#   developer.yahoo.com/performance/rules.html#etagsFileETag None# Zusatzparameter PHP#php_flag zlib.output_compression On# Dateiauflisting unterbindenOptions -Indexes# Kommentieren Sie diese Zeile aus, wenn Sie einen Fehler 500 (Internal Server Error) erhalten#Options +FollowSymlinks<IfModule mod_rewrite.c>	RewriteEngine On	# Javascripte gezip ausliefernRewriteCond %{HTTP:Accept-Encoding} gzipRewriteCond %{REQUEST_FILENAME}.jgz -fRewriteRule (.*)\.js$ $1\.js.jgz [L]AddType "text/javascript" .js.jgzAddEncoding gzip .jgz	#Sicherheit	## Begin - Rewrite rules to block out some common exploits.	# If you experience problems on your site block out the operations listed below	# Block out any script trying to base64_encode data within the URL.	RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]	# Block out any script that includes a <script> tag in URL.	RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]	# Block out any script trying to set a PHP GLOBALS variable via URL.	RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]	# Block out any script trying to modify a _REQUEST variable via URL.	RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})	# Return 403 Forbidden header and show the content of the root homepage	RewriteRule .* index.php [F]	#	## End - Rewrite rules to block out some common exploits.	# Port Scanner	RewriteCond %{HTTP_USER_AGENT} 					^w00tw00t.at.ISC.SANS.DFind	RewriteRule ^.*$ 								403.php [L]	# sitemap.xml auf Dynamische umleiten	RewriteRule ^(.*)sitemap.xml$					sitemap-xml.php [qsappend,L]	Options +SymLinksIfOwnerMatch	# Umleitung auf Adresse mit www, wenn www fehlt und nicht Subdomain und nicht localhost und nicht ssl.webpack.de	RewriteCond %{HTTP:X-Forwarded-Server} 	!^ssl\.webpack\.de$ [NC]	RewriteCond %{HTTP:X-Forwarded-Server} 	!^sslsites\.de$ [NC]	RewriteCond %{HTTP_HOST}   				!^www\..* [NC]	RewriteCond %{HTTP_HOST}   				!^.*\..*\..* [NC]	RewriteCond %{HTTP_HOST}   				!^localhost(.*)$ [NC]	RewriteRule ^(.*)          				http://www.%{HTTP_HOST}/$1 [R=301,L]	###################################################################################################	########	Shopstat - URL Format --- by Webdesign Erfurt	########	##-- Kategorien	RewriteCond %{REQUEST_URI} 								(.*)---([_0-9]+)-([_0-9]+)\.html$	RewriteRule (.*)---([_0-9]+)-([_0-9]+)\.html$ 			index.php?cPath=$2&page=$3 [qsappend,L]	RewriteCond %{REQUEST_URI} 								(.*)---([_0-9]+)\.html$	RewriteRule (.*)---([_0-9]+)\.html$ 					index.php?cPath=$2 [qsappend,L]	##-- Produkte	RewriteRule (.*)--(.+)\.html$ 							product_info.php?products_id=$2 [qsappend,L]	##-- Content	RewriteRule (.*)-_-([0-9]+)\.html$ 						shop_content.php?coID=$2 [qsappend,L]	########	########	####################################################################################################	###################################################################################################	########	Shopstat - URL Format ::: by Shopstat	########	##-- Kategorien	RewriteCond %{REQUEST_URI} 								(.*):::([_0-9]+)-([_0-9]+)\.html$	RewriteRule (.*):::([_0-9]+)-([_0-9]+)\.html$ 			index.php?cPath=$2&page=$3 [qsappend,L]	RewriteCond %{REQUEST_URI} 								(.*):::([_0-9]+)\.html$	RewriteRule (.*):::([_0-9]+)\.html$ 					index.php?cPath=$2 [qsappend,L]	##-- Produkte	RewriteRule (.*)::(.+)\.html$ 							product_info.php?products_id=$2 [qsappend,L]	##-- Content	RewriteRule (.*):_:([0-9]+)\.html$ 						shop_content.php?coID=$2 [qsappend,L]	########	########	####################################################################################################	# immer auf den root verweisen, damit die Startseite (/index.php) nicht zweimal vorkommt	# die folgenden beiden Zeilen auskommentieren wenn Sie eine index.html nutzen wollen	RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/	RewriteRule ^index\.(html?|php)$ http://%{HTTP_HOST}/ [R=301,L]	# Editieren Sie die untenstehende Zeile wenn ihr Shop in einem Unterordner läuft.	# Aber auch wenn Sie einen Fehler 500 (Internal Server Error) bekommen.	# Beispiel: Ist ihr Shop im Verzeichnis www.domain.de/shop ändern Sie die Zeile wie folgt: "RewriteBase /shop/"	#RewriteBase /	RewriteCond %{REQUEST_FILENAME} -f [OR]	RewriteCond %{REQUEST_FILENAME} -d	RewriteRule ^(.+) - [PT,L]	# Alte Kategorien ohne Slash umleiten auf mit slash / Raute in den 4 Zeilen entfernen	#RewriteCond %{REQUEST_URI} !(.*)/$	#RewriteCond %{REQUEST_URI} !\..+$	#RewriteCond %{REQUEST_URI} !/$	#RewriteRule (.*) http://%{HTTP_HOST}/$1/ [R=301,L]	RewriteRule ^(.*)(.+)404.php$								404.php [qsappend,L]	RewriteRule ^(.*)tag/(.*([a-zßöüäA-ZÖÜÄ0-9]))/$ taglisting.php?tag=$1$2 [qsappend,L]	RewriteRule ^(.*)hashtag/(.*([a-zßöüäA-ZÖÜÄ0-9]))$		hashtags.php?hashtags=$1$2 [qsappend,L]	RewriteRule ^(.*)keywords/(.*([a-zßöüäA-ZÖÜÄ0-9]))$		advanced_search_result.php?keywords=$1$2 [qsappend,L]	RewriteRule ^(.*)manufacturer-(.*[0-9])/(.*([a-zßöüäA-ZÖÜÄ0-9]))$	index.php?manufacturers_id=$2 [qsappend,L]	RewriteRule ^(.*)review-(.*[0-9])/(.*([a-zßöüäA-ZÖÜÄ0-9]))$		product_reviews_info.php?reviews_id=$2 [qsappend,L]	##boosted BLOG-START	RewriteRule (.*/)?blog.html blog.php [L]	RewriteCond %{REQUEST_FILENAME} !\.html$ [OR]	RewriteCond %{REQUEST_FILENAME} !\.php$ [OR]	RewriteRule ^(.*)$											commerce_seo_url.php?linkurl=$1 [qsappend,L]</IfModule>ErrorDocument 404 /404.phpErrorDocument 403 /403.php

    Es ist php5.5 akviert. Vielleicht ja jemand eine Lösung eine Möglichkeit wäre sicherlich

    Code
    zlib.output_compression = On

    Aber wie muß das eingebunden werden?
    Alternativ wäre auch noch eine php.ini möglich wenn das leichter geht.

    Habe noch eine php.ini angelegt und dort folgendes eingefügt:

    Code
    zlib.output_compression = On
    
    
    <IfModule mod_deflate.c>
    <FilesMatch "\.(js|css|html|xml)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>

    funktioniert aber auch nicht.
    Danke

    5 Mal editiert, zuletzt von Siggit (11. Dezember 2014 um 23:13)

  • So gehts:

    Schritt 1: php.ini - Datei erstellen.

    Erstellt mit Eurem Texeditor eine Datei mit dem Namen "php.ini" mit folgendem Inhalt:

    Code
    output_handler = Offzlib.output_compression = Onzlib.output_handler = ob_gzhandler


    Speichert die ab und ladet diese ins Root-Verzeichnis Eurer Commerce SEO-Installation.

    Schritt 2: .htaccess-Datei editieren

    Im Root-Verzeichnis der Commerce SEO-Installation befindet sich in der Regel bereits eine .htaccess-Datei.
    Öffnet diese mit einem Text-Editor und fügt folgendes ein:

    Apache Configuration
    <IfModule mod_rewrite.c>RewriteEngine OnRewriteRule ^(.*\.js) gzip.php?type=js&file=$1RewriteRule ^(.*\.css) gzip.php?type=css&file=$1</IfModule>


    Schritt 3: gzip.php - Datei erstellen

    Erstellt eine Datei mit dem Namen "gzip.php" mit folgendem Inhalt:

    Ladet diese Datei nun in das Root-Verzeichnis Eurer Commerce SEO-Installation Testet die Site z.B. mit GTMetrix. Nun sollte alles funktionieren!

    habe die Lösung hier gefunden. Danke nochmals an den Autor.

    Ich hoffe es hilft euch weiter.

  • Hier noch eine Korrektur:

    Die Lebensdauer der js und CSS auf mindestens eine Woche einstellen.Ist hier im Code mit Rot markiert. Ist hier in Sekunden angegeben müßte auch max-age=1 week, gehen.

    PHP
    <?php//check that zlib compression is enabledif(!ini_get('zlib.output_compression')){ die(); }$allowed = array('css','js'); //set array of allowed file types to prevent abuse//check for request variable existence and that file type is allowedif(isset($_GET['file']) && isset($_GET['type']) && in_array(substr($_GET['file'],strrpos($_GET['file'],'.')+1), $allowed)){    $data = file_get_contents(dirname(__FILE__).'/'.$_GET['file']); // grab the file contents    $etag = '"'.md5($data).'"'; // generate a file Etag    header('Etag: '.$etag); // output the Etag in the header    // output the content-type header for each file type    switch ($_GET['type']) {        case 'css':            header ("Content-Type: text/css; charset: UTF-8");        break;        case 'js':            header ("Content-Type: text/javascript; charset: UTF-8");        break;    }    header('Cache-Control: [COLOR='#FF0000']max-age=604800[/COLOR], must-revalidate'); //output the cache-control header    $offset = 60 * 60;    $expires = 'Expires: ' . gmdate('D, d M Y H:i:s',time() + $offset) . ' GMT'; // set the expires header to be 1 hour in the future    header($expires); // output the expires header    // check the Etag the browser already has for the file and only serve the file if it is different    if ($etag == $_SERVER['HTTP_IF_NONE_MATCH']) {        header('HTTP/1.1 304 Not Modified');        header('Content-Length: 0');    } else {        echo $data;    }}?>

    3 Mal editiert, zuletzt von Siggit (10. Dezember 2014 um 20:39)