PHP缓存标头覆盖 [英] PHP cache header override
问题描述
我在这里已经查看了100多个答案,可以尝试很多,没什么用??
I've been through over 100 answers here, lots to try, NOTHING working??
有一个基于PHP的网站。我需要对所有.php文件进行缓存,除了选择少量。
Have a PHP based site. I need caching OFF for all .php files EXCEPT A SELECT FEW.
因此,在.htaccess中,我有以下内容:
So, in .htaccess, I have the following:
ExpiresActive On
# Eliminate caching for certain dynamic files
<FilesMatch "\.(php|cgi|pl)$">
ExpiresDefault A0
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
使用Firebug,我看到以下内容:
Using Firebug, I see the following:
Cache-Control no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform
Connection Keep-Alive
Content-Type text/html
Date Sun, 02 Sep 2012 19:22:27 GMT
Expires Sun, 02 Sep 2012 19:22:27 GMT
Keep-Alive timeout=3, max=100
Pragma no-cache
Server Apache
Transfer-Encoding chunked
X-Powered-By PHP/5.2.17
嘿,看起来不错!
但是,我有几个.php页面,我需要一些
BUT, I have a couple .php pages I need some very short caching on.
我认为简单的答案是将其添加到要启用缓存的每个php页面的顶部:
I thought the simple answer was having this added to the very top of each php page in which I want caching enabled:
<?php header("Cache-Control: max-age=360"); ?>
不是。
然后我尝试了各种以上版本。
Then I tried various versions of the above. Nope.
然后我尝试了元HTTP等效版本。
Then I tried meta http-equiv variations. Nope.
然后我尝试了.htaccess代码的变体以及上述变体,例如将其限制为:
Then I tried variations of the .htaccess code along with the above variations, such as limiting it to:
# Eliminate caching for certain dynamic files
<FilesMatch "\.(php|cgi|pl)$">
Header set Cache-Control "no-cache, max-age=0"
</FilesMatch>
不。
看来我什么都没有这样做将允许将单个.php设置为具有.htaccess代码的缓存启用功能,而无需从.htaccess文件中完全删除该语句。
It seems nothing I do will allow a single .php to be cache enabled with the .htaccess code in place, short of removing the statements from the .htaccess file altogether.
我要去哪里错误?我该怎么做才能使单个php页面可缓存,而其余页面保持关闭?
Where am I going wrong? What do I have to do to get individual php pages to be cacheable while the rest remain off??
谢谢您的任何想法。
推荐答案
好吧,显然这没有答案。因此,我目前的解决方案是完全消除.htaccess代码,并将显式标头应用于每个文件。您所知道的很痛苦,但现在该继续前进了。如果有人有可以使用.htaccess默认值的更优雅的解决方案,请随时分享...谢谢
Well, apparently this has no answer. So, my solution at this point is to eliminate the .htaccess code altogether, and apply explicit headers to each file. A pain in the you-know-what but it's time to move on. If anyone has a more elegant solution that can work with an .htaccess default please feel free to share... thanks
这篇关于PHP缓存标头覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!