0

我正在研究我的网站速度优化。我在使用 gzip 压缩时遇到问题。我把代码放在.htaccess文件里,上传到网上,它不起作用。当我检查这个工具http://www.gidnetwork.com/tools/gzip-test.php它说page content is not compressed。我也用 gtmetrix.com 检查它,但仍然没有运气。

这是我放入.htaccess文件中的代码:

<IfModule mod_deflate.c>
    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
</IfModule>

我也试过没有<IfModule mod_deflate.c></IfModule>

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

在我的 htaccess 中也试过这个方法:

<files *.html>
    SetOutputFilter DEFLATE
</files>

仍然没有运气。难道我做错了什么?如果可以的话请帮忙!

4

1 回答 1

0

对于 Gzipping 您的资产的行为,试试这个。

<FilesMatch "\.(html|php|htm|xml|txt|xsl)$">

    <IfModule mod_expires.c>

     Header set Cache-Control "max-age=7200, must-revalidate"

     Header append Vary Accept-Encoding

     Header append Accept-Encoding "gzip"

    </IfModule>

    </FilesMatch>
于 2013-04-20T20:02:49.433 回答