2011-10-13 61 views

回答

0

this page概述了兩種發送gzip輸出的方法。

最簡單的解決方法是使用輸出緩衝與ob_gzhandler:

<?php 
    ob_start("ob_gzhandler"); 
?> 

的ob_gzhandler將設置正確的頭的照顧。它也不會在客戶端不支持gzip編碼的情況下gzip數據。

但是,ob_gzhandler要求啓用Zlib庫。有關更多詳細信息,請參閱ob_gzhandler的文檔。

0

你可以通過Apache配置來完成。將名爲根.htaccess文件,並把此行是:

<Location /> 
SetOutputFilter DEFLATE 
BrowserMatch ^Mozilla/4 gzip-only-text/html 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html 
SetEnvIfNoCase Request_URI \ 
\.(?:gif|jpe?g|png)$ no-gzip dont-vary 
Header append Vary User-Agent env=!dont-vary 
</Location> 

或simpily只是這一行:

AddOutputFilterByType DEFLATE text/html text/plain text/xml 

更多信息here

+0

非常感謝。但我使用Nginx;) – LotusH