我已更新我的 .htaccess 文件以包含以下内容:
<FilesMatch "\.(css|js)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>
我试图告诉客户端所有 css 和 js 在 1 个月内不会更改,以便他们可以缓存文件。
我有 2 个问题,
- 这是否能实现我想要的
自从添加我现在收到 500 错误后,整个 .htaccess 文件如下:
<前><代码>
;
过期默认“访问权限加 1 个月”
# 开始压缩(DEFLATE)
# 启用压缩
AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript text/html``text/plain text/xml image/x-icon
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# 确保代理提供正确的内容
标头附加 Vary User-Agent env=!dont-vary
# 确保代理正确传送压缩内容
标头附加变化接受编码
# END Compression (DEFLATE)
<代码>
I have updated my .htaccess file to include the following:
<FilesMatch "\.(css|js)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>
I am trying to tell the client that all css and js wont change for 1 month so they can cache they files.
I have 2 questions,
- Is this going to achieve what I want
-
Since adding that I am now getting a 500 error, the whole .htaccess file is below:
<FilesMatch "*\.(css|js)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>
# BEGIN Compression (DEFLATE)
<IfModule mod_deflate.c>
# Enable compression
AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript text/html ``text/plain text/xml image/x-icon
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
# Make sure proxies deliver correct content
Header append Vary User-Agent env=!dont-vary
# Ensure proxies deliver compressed content correctly
Header append Vary Accept-Encoding
</IfModule>
</IfModule>
# END Compression (DEFLATE)
发布评论
评论(1)
确保在
ExpiresDefault
之前在 FilesMatch 指令内设置ExpiresActive ON
。Make sure
ExpiresActive ON
is set inside of your FilesMatch directive beforeExpiresDefault
.