CodeIgniter GZIP压缩问题 [英] CodeIgniter GZIP compression issue
本文介绍了CodeIgniter GZIP压缩问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用CodeIgniter HMVC开发网站.
I am developing a website using CodeIgniter HMVC.
- 我已在服务器(cPanel)中启用了GZIP压缩.
- 我已在CodeIgniter Config(
$ config ['compress_output'] = TRUE;
) 中启用了压缩 - 我在
index.php
文件顶部添加了ob_start("ob_gzhandler");
. - 我已在
.htaccess
文件中添加了DEFLATE.
- I have enabled GZIP Compression in server(cPanel).
- I have enabled compression in CodeIgniter Config(
$config['compress_output'] = TRUE;
) - I have added
ob_start("ob_gzhandler");
at top of theindex.php
file. - I have added DEFLATE in
.htaccess
file.
当我测试根域( https://seocompany.us.com/)是GZIP压缩.
When I test the root domain(https://seocompany.us.com/) is GZIP compressed.
但是当我测试其他任何页面时( https://seocompany.us.com/services ),错误显示未启用GZIP.
But when I test any other pages(https://seocompany.us.com/services), error shows GZIP is not enabled.
推荐答案
如果您在cPanel中做到了,那就足够了.
If you did it in cPanel thats probably enough.
或者您可以在htaccess中执行此操作
Or you canJust do this in 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>
这篇关于CodeIgniter GZIP压缩问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文