我正在使用Google Page Insights来测试我的网页,并建议我启用缓存控制和通缩。所以我打开了所需的模块(mod_cache.so,mod_deflate.so,mod_headers.so,mod_filter.so,mod_expires.so)并修改了我将在下面包含的.htaccess文件。 Google Page Insights仍然无法接受压缩,出于某种原因.png图片不会被缓存。请指教......
RewriteEngine On
<IfModule mod_expires.c>
ExpiresActive On
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# Your document html
ExpiresByType text/html "access plus 4 hours"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"
# Favicon
ExpiresByType image/x-icon "access plus 1 year"
# Media: images, video, audio
ExpiresByType image/gif "access plus 2 weeks"
ExpiresByType image/png "access plus 2 weeks"
ExpiresByType image/jpg "access plus 2 weeks"
ExpiresByType image/jpeg "access plus 2 weeks"
ExpiresByType video/ogg "access plus 2 weeks"
ExpiresByType audio/ogg "access plus 2 weeks"
ExpiresByType video/mp4 "access plus 2 weeks"
ExpiresByType video/webm "access plus 2 weeks"
# HTC files
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
<IfModule mod_deflate_c.>
SetOutputFilter DEFLATE
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>