【问题标题】:mod deflate not compressing subdirectories of rootmod deflate 不压缩根目录的子目录
【发布时间】:2012-12-02 00:15:03
【问题描述】:

我在尝试解决 gzip 放气问题大约 48 小时后意识到我可能需要寻求帮助,呵呵。

在意识到我需要在我的 php.ini 文件中打开压缩后,我终于通过 .htaccess 在我的共享 Unix 服务器上启用了 deflate 模块。

PageSpeed 告诉我,我的根 HTML 是用 gzip 为网站编码的,我为 Wordpress 网站 theoleandersofsanleon.com 获得了 77.3% 的压缩率,但任何子目录中的文件都没有被压缩(主要是 css 和 js 文件在我的 wordpress 目录及其子目录中)。

我认为没有必要,但我继续尝试使用指令目录,然后使用指令位置无济于事。

如果您需要查看任何服务器规范,我会将 phpinfo.php 文件放在根目录中。

这是我的 .htaccess 文件中针对我的 htdocs 目录和 wordpress 目录的内容:

<IfModule mod_deflate.c>
# Insert filters
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
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml

# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

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

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

如果您需要更多信息,请告诉我,非常感谢您的帮助,我们将不胜感激,我将能够开始让我的头发重新长出来 8-)

【问题讨论】:

  • 感谢您的回复。我阅读了有关 Gzip 和 deflate 的文档大约 12 个小时,我读到的每一件事都同意 Gzip 是旧版本(用于 Apache 1.3)并且 deflate 是新版本,Gzip 在 Apache 2.0 之后被弃用但是,那并没有这并不意味着所有这些文档都没有错。我在 .htaccess 中启用了至少 5 种不同的压缩方式,直到我打开 zlip 输出它才会起作用。我还在整个过程的每一步都删除了浏览器缓存。你有关于我问的问题的任何信息吗?再次感谢您的回复。
  • 对不起。你是对的。 mod_deflate 优于 mod_gzip。我不知道我为什么写这个,尽管在我的辩护中 mod_deflate 实际上使用 gzip 与它的名字相反。我会删除我的评论,以免混淆其他人。
  • 没问题。不过有一件奇怪的事情,我查看了我的 php.ini,它说 mod_deflate 已安装,即使你注意到了,我的服务器正在运行 Apache 1.3.42。无论哪种方式,我最终都从我的 htaccess 中删除了指令并安装了 WT3C。现在它显示它正在使用 Gzip(这对 1.3 有意义)并且正在压缩我所有的 css 和 js,但不是我的主页 html,哈哈!所以现在我遇到了与我最初遇到的完全相反的问题 8-) 哦,好吧,网站现在快一点了,我们看看我是否最终不能让等式的两边都起作用......跨度>
  • 啊哈。我只是在查看网站,并通过 gzip 压缩返回了 css。但是为什么还要使用 apache 1.3.42 呢?那个版本已经快 3 年了。

标签: wordpress .htaccess gzip deflate


【解决方案1】:

在您的顶级 .htaccess 文件中试试这个。这是在 cPanel 中使用优化器时生成的内容。

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
  <IfModule mod_setenvif.c>
    # 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
  </IfModule>

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

【讨论】:

  • 嗨,马克,感谢您的意见。在安装 WT3C 之后,看起来所有这些都包含在 htaccess 文件中。这是我现在的 htaccess(仍然只压缩 css 和 js,gzip 测试失败):theoleandersofsanleon.com/stack/htaccessStack.txt 再次感谢。
  • 我可以看到您的 htaccess 文件没有任何问题。我能想到的最好的建议是更新 Apache,但老实说,这只是我会尝试的事情,并不完全相信它会有所作为:)
  • 太棒了。感谢您检查马克。真的很感谢你。我会咨询我的主人,看看他们为什么运行旧的 Apace 并从那里开始。
  • @WillRichards 你设法解决了这个问题吗?我遇到了同样的问题,无法解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-18
  • 2011-12-31
  • 1970-01-01
  • 2019-12-09
  • 2011-01-29
  • 2018-12-10
  • 1970-01-01
相关资源
最近更新 更多