好吧,我检查了很多网站,了解如何使用.htaccess文件管理浏览器的缓存,但是对我来说仍然不清楚.
Ok, I checked a lot of websites about how to manage the browser's cache memory with a .htaccess file, but it is still very not clear to me.
我想将特定文件缓存一个月.对于其余的内容,我希望每次都可以刷新.所以我尝试了:
I want to cache specific files for one month. For the rest, I want it to be refreshed every time. So I tried:
<IfModule mod_headers.c> Header unset Cookie Header unset Set-Cookie Header unset Cache-Control Header unset ETag FileETag none </IfModule> <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "now" <Files "/css/jquery-ui.css"> ExpiresDefault "access plus 1 month" </Files> <Files "/js/jquery-1.10.2.min.js"> ExpiresDefault "access plus 1 month" </Files> <Files "/js/jquery-ui.js"> ExpiresDefault "access plus 1 month" </Files> <Files "/js/analytics.js"> ExpiresDefault "access plus 1 month" </Files> <Files "/matheos/img/*"> ExpiresDefault "access plus 1 month" </Files> <Files "/img/*"> ExpiresDefault "access plus 1 month" </Files> </IfModule>但是它不能完全按预期工作...
But it doesn't work exactly as expected...
正确地没有缓存HTML,但是也没有缓存诸如jquery-ui.css之类的特定文件,这些文件应被缓存1个月.
The HTML is correctly not cached, but the specific files like jquery-ui.css, which should be cached for 1 month, are also not cached.
无论如何,这个.htaccess对您来说还好吗?
Anyway, does this .htaccess seem ok for you ?
推荐答案好,知道了!要定位特定文件,正确的语法是:
Ok, got it ! To target a specific file, the correct syntax is :
# to not cache css except jquery-ui.css ExpiresByType text/css "now" <FilesMatch "jquery-ui\\.css$"> ExpiresByType text/css "access plus 1 month" </FilesMatch>这是对我有用的唯一方法,至少在ovh共享主机的情况下.我还尝试了ExpiresDefault的所有可能组合,但是没有用...
This is the only way that worked for me, at least in the case of an ovh shared host. I also tried all possible combinations with ExpiresDefault but it didn't work...
更多推荐
htaccess/mod
发布评论