magento htaccess gzip无法正常工作

时间:2013-11-28 16:47:52

标签: .htaccess magento gzip

我试图在magento中启用gzip,但它不起作用 我按照一些步骤 喜欢 启用 php_flag zlib.output_compression on 比检查phpinfo()和gzip显示启用比我的magento htacess我添加代码

但是当我在gtmatrix或google pagespeed中检查时,它会要求进行gzip压缩

<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>

以上代码无效,所以我试过

<filesMatch "\.(js|css)$">
Header set Content-Encoding x-deflate
# Header set Content-Encoding compress
# Header set Content-Encoding x-gzip
</filesMatch>

但是当我添加这个我的css和js停止工作我应该怎么做才能启用它?

2 个答案:

答案 0 :(得分:0)

您是否已从服务器启用?请检查那些扩展

答案 1 :(得分:0)

在.htaccess文件中添加此代码以启用gzip压缩 -

<IfModule mod_deflate.c>

############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

    # Insert filter on all content
    SetOutputFilter DEFLATE

    # Insert filter on selected content types only
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

    # 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

    # 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>