CodeIgniter GZIP压缩问题

时间:2017-03-17 11:10:20

标签: php .htaccess codeigniter gzip

我正在使用CodeIgniter HMVC开发一个网站。

  1. 我在服务器(cPanel)中启用了GZIP压缩。
  2. 我在CodeIgniter配置($config['compress_output'] = TRUE;
  3. 中启用了压缩功能
  4. 我在ob_start("ob_gzhandler");文件的顶部添加了index.php
  5. 我在.htaccess文件中添加了DEFLATE。
  6. 当我测试根域(https://seocompany.us.com/)时,GZIP是压缩的。

    但是当我测试任何其他页面(https://seocompany.us.com/services)时,错误显示GZIP未启用。

1 个答案:

答案 0 :(得分:1)

如果你在cPanel中做到的话可能已经足够了。

或者你只能在htaccess中执行此操作

# Force compression for mangled headers.
# http://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
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
#  and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
#  as `AddOutputFilterByType` is still in the core directives).
<IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
                                  application/javascript \
                                  application/json \
                                  application/ld+json \
                                  application/rss+xml \
                                  application/vnd.ms-fontobject \
                                  application/x-font-ttf \
                                  application/x-web-app-manifest+json \
                                  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>