为浏览器缓存启用mod_expires

Atr*_*rag 5 apache .htaccess caching browser-cache

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
Run Code Online (Sandbox Code Playgroud)

有什么理由不支持浏览器缓存?我正在运行Centos 5并确保安装了expires模块.

shu*_*304 1

尝试使用这个...通过文件扩展名...根据您的需要更改 max-age

甚至使用 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>
Run Code Online (Sandbox Code Playgroud)