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

PHP
PHP实现网页自动更新块
PHP 5.0 中的对象重载技术研究
轻型数据库SQLite结合PHP的开发
PHP中模板分页的处理
在debian下为PHP5.0.3安装pdo模块
PHP下实现端口复用/劫持
PHP链接ACCESS数据库最简单的方法
IIS 不用 rewrite 实现页面静态化的方法
PHP发现安全漏洞
Windows下PHP4.0与Oracle 8的连接设置
使用OOP技术来优化PHP应用程序
用MySQL和PHP创建XML
正则表达式中的特殊字符一览
截获网站
在UNIX平台上的Netscape Enterprise Server 3.x下配置PHP
Windows 98下安装Apache(PWS) PHP4MySQLphpMyAdmin的方法
对《Windows 9x/NT下以Apache的模块方式安装PHP4》的补充
Windows2000下安装Apache PHP4 MySQL
在WIN98下安装PHP4+ PERSONAL ORACLE8I
在 PHP 中用描点法“绘制”中文

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-04   浏览: 245 ::
收藏到网摘: 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文件里吧。