无法启用压缩(deflate / gzip)

时间:2014-01-13 22:11:53

标签: .htaccess compression gzip deflate

由于YSlow仍建议在我的网站http://www.donboscoeltern.de上启用压缩,我试过在.htaccess文件中包含以下代码片段(下面列出的是最后3个版本):


# 1
<ifModule mod_gzip.c>  
mod_gzip_on Yes  
mod_gzip_dechunk Yes  
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$  
mod_gzip_item_include handler ^cgi-script$  
mod_gzip_item_include mime ^text/.*  
mod_gzip_item_include mime ^application/x-javascript.*  
mod_gzip_item_exclude mime ^image/.*  
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*  
</ifModule>  

# 2
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
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

# 3
<ifmodule mod_deflate.c>
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</ifmodule>

以上版本都没有导致任何更改:使用gtmetrix等测试都表示网站http://www.donboscoeltern.de仍然没有被压缩。

你有什么想法吗? 谢谢!

的问候,
Vlad Ghitulescu

1 个答案:

答案 0 :(得分:1)

奇怪行为的原因 - 对于通过.htaccess文件进行压缩的不同方法没有任何反应是托管公司:他们关闭了mod_gzip-module用于入门级托管(我有)。他们的解决方案:买下一个级别!

感谢提示,cubitouch!

亲切的问候, 维拉德