在我的公司,我们有htaccess文件,其中没有启用网页缓存,我想启用一个单一的API缓存,但htaccess文件是覆盖我的缓存控制,我通过头函数设置。有人能帮助我吗?
htaccess文件
<ifModule mod_headers.c>
#BEGIN Security Headers
Header set X-XSS-Protection "1; mode=block"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-Content-Type-Options "nosniff"
#END Security Headers
# BEGIN Cache-Control Headers
#To disable ETags
Header unset ETag
<filesMatch "\.(ico|jpe?g|png|gif|swf|woff)$">
Header set Cache-Control "max-age=86400, public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, no-store, no-cache, must-revalidate, max-age=0"
Header set Pragma "no-cache"
</filesMatch>
# END Cache-Control Headers
我的api php文件
header("Pragma: cache");
header("Cache-Control: max-age=300");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 300) . " GMT");
header('Last-Modified: ' . gmdate("D, d M Y H:i:s", time()) . ' GMT');
header('Content-Type: application/json');
1条答案
按热度按时间7tofc5zh1#
apache中有一个属性setfempty,它适用于2.2以上的版本,但对我来说,它是2.2,所以我用下面的命令替换了setfempty
上面的代码是经过编辑的,它已经为我工作了