首页 文章

GZIP压缩不工作 - htaccess文件可能有误?

提问于
浏览
0

我有最糟糕的时间让我的服务器压缩我的文件 . 我使用ipage作为我的主机,运行apache II . 当我查看谷歌开发者工具中的“ Headers ”区域时,它说文件'accept-encoding':gzip,deflate,sdch',但是pagespeed的见解仍然告诉我我的文件没有被gzip压缩 . 这是我的htaccess文件代码:

这也许有帮助:http://www.uniconutrition.com/info.php

请帮忙!

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^uniconutrition.com [nc]
rewriterule ^(.*)$ http://www.uniconutrition.com/$1 [r=301,nc]

<IfModule mod_deflate.c>
  <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>

2 回答

  • 1

    创建一个名为info.php的小文件,输入“phpinfo()”并检查是否包含ZLib .

    这一点通常对我有用:

    <IfModule mod_deflate.c>
        <IfModule mod_php5.c>
            php_flag zlib.output_compression 1
            php_value zlib.output_compression_level 7
        </IfModule>
    
        AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
        AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
        AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    
        <FilesMatch "\.(ttf|otf|eot|svg)$" >
            SetOutputFilter DEFLATE
        </FilesMatch>
    </IfModule>
    

    Aditionally ,请注意我不确定将黑色标记作为分隔符/间隔符使用't have all your mimetypes included. :) I' .

  • 1

    检查你是不是通过一个代理,在下载时解压缩内容?

    我刚检查了你用cURL提供的URL(没有代理),并且至少在HTML请求时显示为gzip'ed:

    $ curl -I -H"Accept-Encoding: gzip" http://www.uniconutrition.com/info.php
    HTTP/1.1 200 OK
    Date: Fri, 19 Jul 2013 14:54:15 GMT
    Server: Apache/2
    X-Powered-By: PHP/5.2.17
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Connection: close
    Content-Type: text/html
    

    但是,CSS和JS不是,例如http://www.uniconutrition.com/java/main.jshttp://www.uniconutrition.com/css/bootstrap.css

    我怀疑你的网络服务器正在使用mod_deflate而不是mod_filter . 另外值得注意的是,在你的例子中,你使用的是错误的mimetype for JS,应该是 application/x-javascript 而不是 application/javascript .

    因此,您应该添加一个(更简单的)指令,如下所示:

    <IfModule mod_deflate.c>
       AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
    </IfModule>
    

    EDIT:

    再看看,你的重写规则也不起作用;它指定所有流量都应该重定向到www.uniconutrition.com,但是这没有发生,所以htaccess文件的其余部分也被忽略了 . 请咨询您的主人 .

相关问题