我怎样才能获得Apache的gzip的COM pression工作? [英] How can I get Apache gzip compression to work?

查看:225
本文介绍了我怎样才能获得Apache的gzip的COM pression工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让我的网站用gzip COM pression。

最近我看了这部<一个href="http://css-tricks.com/video-screencasts/114-lets-do-simple-stuff-to-make-our-websites-faster/">video克里斯Coyier了在css-tricks.com。在视频中,他谈到启用gzip的COM pression使网站运行速度更快。

根据他的指示,我经由html5boilerplate.com链接到github上,从他们的.htaccess文件复制gzip的COM pression code,粘贴到我自己的,并将其上传到我的网站。

我通过gzipwtf.com测试,它似乎并没有工作。谁能帮我这个?

我的.htaccess文件看起来是这样的:

 #------------------------------------- ---------------------------------
#修剪WWW
#------------------------------------------------- ---------------------

RewriteEngine叙述上
的RewriteCond%{HTTP_HOST}!^ orbitprint.com $ [NC]
重写规则^(。*)$ http://orbitprint.com/$1 [L,R = 301]

#------------------------------------------------- ---------------------
#Gzip已融为一体pression
#------------------------------------------------- ---------------------

&LT; IfModule mod_deflate.c&GT;

  #强制放气的错位头developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  &LT; IfModule mod_setenvif.c&GT;
    &LT; IfModule mod_headers.c&GT;
      SetEnvIfNoCase ^(接受-EncodXng | X-CEPT-编码| X {15} |〜{15} |  -  {15})$ ^((GZIP |?放气)\ S * \ S *)+ | [X〜 - ] {4,13} $ HAVE_Accept,编码
      RequestHeader追加接受编码的gzip,紧缩ENV = HAVE_Accept,编码
    &LT; / IfModule&GT;
  &LT; / IfModule&GT;

  #的COM preSS标有以下MIME类型之一,所有输出
  &LT; IfModule mod_filter.c&GT;
    AddOutputFilterByType DEFLATE应用程序/原子+ XML \
                                  应用程序/ JavaScript的\
                                  应用程序/ JSON \
                                  应用程序/ RSS + XML \
                                  应用程序/ vnd.ms-fontobject \
                                  应用程序/ x-字体TTF \
                                  是application / xhtml + xml的\
                                  应用程序/ XML \
                                  字体/ OpenType字体\
                                  图像/ SVG + XML \
                                  图片/ X-图标\
                                  文/ CSS \
                                  文/ HTML \
                                  纯文本/ \
                                  文/ x分量\
                                  文/ XML
  &LT; / IfModule&GT;

&LT; / IfModule&GT;
 

解决方案

试试这个:

  ####################
#GZIP COM preSSION#
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text / html的文/ CSS文本/纯文本/ XML应用程序/ x-的JavaScript应用程序/ x-httpd的,PHP
BrowserMatch ^的Mozilla / 4 GZIP只-text / html的
BrowserMatch ^的Mozilla / 4 \ .0 [678]无GZIP
BrowserMatch \ bMSIE!没有GZIP!GZIP只-text / html的
BrowserMatch \ BMSI [E]!没有GZIP!GZIP只-text / html的
SetEnvIfNoCase REQUEST_URI \。(?: GIF |?JPE G | PNG)$无gzip压缩
头追加因人而异用户代理包膜=!不,变化
 

I can't get my site to use gzip compression.

I recently watched this video by Chris Coyier over at css-tricks.com. In the video, he talks about enabling gzip compression to make websites run faster.

As per his instruction, I linked through to github via html5boilerplate.com, copied the gzip compression code from their .htaccess file, pasted it into my own, and uploaded it to my site.

I've tested it via gzipwtf.com and it doesn't seem to work. Can anyone help me with this?

My .htaccess file looks like this:

# ----------------------------------------------------------------------
# Trim www
# ----------------------------------------------------------------------

RewriteEngine On
RewriteCond %{HTTP_HOST} !^orbitprint.com$ [NC]
RewriteRule ^(.*)$ http://orbitprint.com/$1 [L,R=301]

# ----------------------------------------------------------------------
# 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>

  # Compress all output labeled with one of the following MIME-types
  <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
                                  application/javascript \
                                  application/json \
                                  application/rss+xml \
                                  application/vnd.ms-fontobject \
                                  application/x-font-ttf \
                                  application/xhtml+xml \
                                  application/xml \
                                  font/opentype \
                                  image/svg+xml \
                                  image/x-icon \
                                  text/css \
                                  text/html \
                                  text/plain \
                                  text/x-component \
                                  text/xml
  </IfModule>

</IfModule>

解决方案

Try this :

####################
# GZIP COMPRESSION #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary

这篇关于我怎样才能获得Apache的gzip的COM pression工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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