gpt4 book ai didi

PHP 缓存 header 覆盖

转载 作者:可可西里 更新时间:2023-11-01 00:48:36 25 4
gpt4 key购买 nike

我已经在这里回答了 100 多个答案,尝试了很多,但没有任何效果??

拥有一个基于 PHP 的网站。我需要关闭所有 .php 文件的缓存,除了少数几个。

因此,在 .htaccess 中,我有以下内容:

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,我看到以下内容:

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 页面需要一些非常短的缓存。

我认为简单的答案是将其添加到我希望启用缓存的每个 php 页面的最顶部:

<?php header("Cache-Control: max-age=360"); ?>

没有。

然后我尝试了上面的各种版本。不。

然后我尝试了 meta http-equiv 变体。不。

然后我尝试了 .htaccess 代码的变体以及上述变体,例如将其限制为:

# Eliminate caching for certain dynamic files
<FilesMatch "\.(php|cgi|pl)$">
Header set Cache-Control "no-cache, max-age=0"
</FilesMatch>

没有。

似乎我做的任何事情都不允许使用 .htaccess 代码在适当的位置启用单个 .php 缓存,除了从 .htaccess 文件中完全删除语句。

我哪里错了?我需要做什么才能让单个 php 页面可缓存,而其余页面保持关闭??

感谢您的任何想法。

最佳答案

好吧,显然这没有答案。因此,此时我的解决方案是完全消除 .htaccess 代码,并将显式 header 应用于每个文件。你知道什么的痛苦,但现在是继续前进的时候了。如果有人有更优雅的解决方案可以使用 .htaccess 默认值,请随时分享...谢谢

关于PHP 缓存 header 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12239225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com