【问题标题】:Enable mod_expires for browser caching为浏览器缓存启用 mod_expires
【发布时间】:2018-05-05 09:32:02
【问题描述】:

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 模块。

【问题讨论】:

  • 您是否尝试通过sudo a2enmod expires 加载它,然后检查它是否加载了apachectl -M
  • 感谢您的评论,但 Centos 不使用 a2enmod。

标签: apache .htaccess caching browser-cache


【解决方案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>

【讨论】:

    猜你喜欢
    • 2017-01-20
    • 2014-07-27
    • 2011-03-24
    • 2020-07-19
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多