当前位置: 首页 > 图文教程 > 网络编程 > PHP > 采用.htaccess设置网站的压缩与缓存

PHP
PHP教程:缓存技术应用
PHP5对webservice的实现
20个有用的PHP+jQuery组件和教程(英文)
屏蔽部分Email地址的smarty插件
编写PHP代码的过程中养成的良好习惯
PHP教程:MySQL读写分离由PHP实现
PHP实例教程:实现网站上传图片自动加水印
CSS教程:绝对定位和浮动的分栏布局
WordPress教程:query_posts()
总结 PHP xajax应用方法
如何实现PHP的TEA算法?
PHP的企业应用-WebService
PHP的光明前途
如何在IIS7下面添加对PHP网页的支持
用php制作友好的404错误页面
多进程应用帮助PHP解决难题
PHP数据库常出现哪些问题?
PHP的七大优势
PHP教程:TEA算法实现
纯属忽悠:Google提供的网站加速PHP技巧

PHP 中的 采用.htaccess设置网站的压缩与缓存


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-04   浏览: 271 ::
收藏到网摘: n/a

原文标题:设置blog的缓存和压缩

在网站根目录下的.htaccess文件中添加以下代码

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType text/css A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType text/javascript A2592000
ExpiresByType text/html A600
</IfModule>

<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|html|htm)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
</FilesMatch>

FileETag none

现在使用Firefox的YSlow插件,以Small Site or Blog标准测试的分数为99分,以YSlow2(V2)标准测试的分数为94分,被扣掉的几分主要是因为没有使用CDN。所以现在速度已经被优化到了极致。

赶快把它放到你的网站或blog根目录下的.htaccess文件里吧。