【发布时间】:2012-12-09 22:56:14
【问题描述】:
我可以同时拥有两个 .htaccess 吗:
DEFLATE
在 php、图像、html 文件等 + php 标头中:
ob_start("gzhandler") ?
如果不是,最好的机会是什么?我只是担心它是否会发生冲突。
【问题讨论】:
标签: php compression gzip http-compression
我可以同时拥有两个 .htaccess 吗:
DEFLATE
在 php、图像、html 文件等 + php 标头中:
ob_start("gzhandler") ?
如果不是,最好的机会是什么?我只是担心它是否会发生冲突。
【问题讨论】:
标签: php compression gzip http-compression
对图像使用压缩通常不是一个好主意,因为网络上大多数广泛使用的图像格式已经被压缩,因此您只会给文件增加不必要的开销。您通常希望对本质上是文本的资源(HTML、CSS、JavaScript 等)使用压缩,因为这些资源的压缩率非常高。
至于问题本身,据我所知,不可能同时使用DEFLATE 和GZIP,但老实说,因为我从来没有尝试过这样的事情,请多多包涵如果此信息不正确。
至于选择哪一个,我强烈建议您看看下面的帖子,您可以看到DEFLATE 和GZIP 的一些优缺点。
Why use deflate instead of gzip for text files served by Apache?
我个人尽可能使用DEFLATE,因为有时通过.htaccess 实现它比查看代码更容易。我也喜欢在测试或开发东西时快速禁用该功能的可能性。
Apache Server Configs 项目有一个非常全面的 .htaccess 文件,因此您可能需要查看该项目 HERE。
现在虽然该文件非常全面,但您可能只想使用正常情况下的配置,如下所示:
# -----------------------------------------------------------------------
# Defining MIME types to ensure the web server actually knows about them.
# -----------------------------------------------------------------------
<IfModule mod_mime.c>
AddType application/javascript js
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
</Ifmodule>
# -----------------------------------------------------------------------
# Compressing output.
# -----------------------------------------------------------------------
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</Ifmodule>
【讨论】:
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component 行在 Windows 7(所有浏览器)上产生了一个大错误,其中网站根本无法交付(cPanel,带有 URL 重写的 TYPO3)。我把它注释掉了。
.htaccess 现在使用了稍微不同的语法。我更新了我的答案。