Speeding up Websites via Simple Apache Settings in Htaccess [zlib.output_compression + mod_deflate] a Syntax

陌路散爱 提交于 2019-12-08 07:00:14

问题


Imagine these two chunks of code residing in htaccess for speeding up the website.
With php 5.2.3 on apache 2.0

block A

# preserve bandwidth for PHP enabled servers
<ifmodule mod_php4.c>
    php_value zlib.output_compression 16386
</ifmodule>

block B

# compress speficic filetypes
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|eot|ttf|svg|xml|ast|php)$">
    SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

Questions that arise:

Q1. Is this the proper way to combine these two blocks A + B into 1 htaccess in the root?

Q2. Is it correct that on the second block B, |php| is used again in the mod_edflate?


回答1:


If mod_deflate is loaded and you can control apache configuration then you should let apache do output compression. Doing compression in php is always going to be slower. Here is my recommended config for your htaccess:

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
</IfModule>

I think a blacklist is more effective in this case since there are very few types of files you don't want compressed. This way you make sure to compress everything else, even those types of files you can't remember to add to a whitelist.



来源:https://stackoverflow.com/questions/5412681/speeding-up-websites-via-simple-apache-settings-in-htaccess-zlib-output-compres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!