【问题标题】:magento htaccess gzip not workingmagento htaccess gzip不工作
【发布时间】:2024-01-08 02:41:02
【问题描述】:

我尝试在 magento 中启用 gzip,但它不起作用 我遵循了一些步骤 像 使能够 php_flagzlib.output_compressionon 比检查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 停止工作我应该怎么做才能启用它?

【问题讨论】:

  • 你试过重启apache吗??

标签: .htaccess magento gzip


【解决方案1】:

您是否从服务器启用?请检查扩展名

【讨论】:

    【解决方案2】:

    在您的 .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>
    

    【讨论】: