【发布时间】:2019-03-21 05:17:44
【问题描述】:
我正在尝试将过期标头添加到除某些特定文件之外的所有文件。事实上,我正在使用一个缓存工具,它将以下代码添加到我的 htaccess 中:
# BEGIN LBCWpFastestCache
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|webp|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
AddType application/font-woff2 .woff2
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/webp A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/svg+xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType application/font-woff2 A2592000
</IfModule>
<IfModule mod_headers.c>
Header set Expires "max-age=2592000, public"
Header unset ETag
Header set Connection keep-alive
FileETag None
</IfModule>
</FilesMatch>
# END LBCWpFastestCache
我想为我页面上的两个不同图像设置一个例外。让他们的名字是 file-a 和 file-b,这是我尝试过的:
我把这段代码放在插件代码之后。
<FilesMatch "\.(file-a|file-b)$">
ExpiresDefault "access plus 1 hour"
</FilesMatch>
既然这样不行,我也试过把它放在代码前面,也不管用。
然后我尝试操作插件添加的代码的FilesMatch 部分,以便它排除我的文件。
<FilesMatch "(?!.*/(file-a|file-b))(\.(ico|pdf|flv|jpg|jpeg|png|gif|webp|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$)">
也没有用。
我如何做到这一点?
【问题讨论】:
标签: .htaccess caching expires-header