针对windows版本的apache2.2,开启方法如下:
第一步:
找到apache的配置文件httpd.conf,找到下面两行,将前面的 # 去掉.
- LoadModule deflate_module modules/mod_deflate.so
- LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule expires_module modules/mod_expires.so
重启apache服务器.
第二步:
打开网站的 .htaccess 文件,将下面代码拷贝进去:
- <IfModule mod_expires.c>
- ExpiresActive On
- ExpiresDefault "access plus 12 month"
- ExpiresByType text/html "access plus 12 months"
- ExpiresByType text/css "access plus 12 months"
- ExpiresByType image/gif "access plus 12 months"
- ExpiresByType image/jpeg "access plus 12 months"
- ExpiresByType image/jpg "access plus 12 months"
- ExpiresByType image/png "access plus 12 months"
- EXpiresByType application/x-shockwave-flash "access plus 12 months"
- EXpiresByType application/x-javascript "access plus 12 months"
- ExpiresByType video/x-flv "access plus 12 months"
- </IfModule>
- <IfModule mod_deflate.c>
- SetOutputFilter DEFLATE
- AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
- </IfModule>
代码没错,测试通过了的,大家可以放心使用.
效果如下:
网址 http://www.k686.com/ 检测结果如下:
是否压缩 是
压缩类型 gzip
原始文件大小 91844 字节
压缩后文件大小 15365 字节
压缩率(估计值) 83.27%
Header信息
Date Thu, 03 Jun 2010 09:00:14 GMT
Server Apache/2.2.11 (Win32) PHP/5.2.10
X-Powered-By PHP/5.2.10
Set-Cookie PHPSESSID=nkcqphhqt8005prgnn35fdfif4; path=/
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control private
Pragma no-cache
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 15365
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html; charset=utf-8