巧用.htaccess设置网站的压缩与缓存
原文转载地址:http://www.jb100.net/html/content-22-738-1.html
在网站根目录下的.htaccess文件中添加以下代码 <IfModule mod_expires.c> <code class="prettyprint linenums lang-php"> <IfModule mod_expires.c> <br>
ExpiresActive On <br>
ExpiresByType image/gif A2592000 <br>
ExpiresByType image/jpeg A2592000 <br>
ExpiresByType image/png A2592000 <br>
ExpiresByType application/x-shockwave-flash A2592000 <br>
ExpiresByType text/css A2592000 <br>
ExpiresByType application/x-javascript A2592000 <br>
ExpiresByType application/javascript A2592000 <br>
ExpiresByType text/javascript A2592000 <br>
ExpiresByType text/html A600 <br>
</IfModule> <br>
<br>
<IfModule mod_deflate.c> <br>
<FilesMatch ".(js|css|html|htm)$"> <br>
SetOutputFilter DEFLATE <br>
</FilesMatch> <br>
</IfModule> <br>
<br>
<ifModule mod_gzip.c> <br>
mod_gzip_on Yes <br>
mod_gzip_dechunk Yes <br>
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ <br>
mod_gzip_item_include handler ^cgi-script$ <br>
mod_gzip_item_include mime ^text/.* <br>
mod_gzip_item_include mime ^application/x-javascript.* <br>
mod_gzip_item_exclude mime ^image/.* <br>
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* <br>
</ifModule> <br>
<br>
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css)$"> <br>
Header unset Last-Modified <br>
</FilesMatch> <br>
<br>
FileETag none
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