启用mod_expires实现浏览器缓存

5

htaccess文件长这样:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]




</IfModule>
<IfModule mod_expires.c>


# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"

# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
# CSS
ExpiresByType text/css "access plus 1 week"
# Javascript
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/html "access plus 1 day"
</IfModule>

# END WordPress

这个操作有没有成功开启浏览器缓存?我正在使用Centos 5,已经确保安装了Expires模块。


1
你尝试过通过 sudo a2enmod expires 加载它,然后检查是否已加载 apachectl -M 吗? - Abhishek Gurjar
谢谢您的评论,但Centos不使用a2enmod。 - Atrag
1个回答

1
尝试使用此方法...按文件扩展名...更改最大年龄以满足您的需求,并使用DEFLATE来压缩下载大小。
# 1 YEAR = 29030400 || 2 DAYS = 172800 || 1 MIN = 60
# 1 WEEK = 604800
<filesMatch "\.(jpg|jpeg|png|gif|swf|xml|txt|css|js|ico|pdf|flv|html|htm)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>

#compress
<filesMatch "\.(js|css|json|html|xml)$">
SetOutputFilter DEFLATE
</filesMatch>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接