0

如果我在我的全局 .htaccess 中使用以下内容,我在 php 文件上确实存在缓存和 ModExpire 的巨大问题

<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresByType text/css "access plus 1 month"
 ExpiresByType text/javascript "access plus 1 month"
 ExpiresByType text/html "access plus 600 seconds"
 ExpiresByType application/javascript "access plus 1 month"
 ExpiresByType application/x-javascript "access plus 1 month"
 ExpiresByType application/xhtml-xml "access plus 600 seconds"
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
<ifmodule mod_headers.c>
 <filesmatch "\\.(ico|jpe?g|png|gif|swf)$">
  Header set Cache-Control "max-age=2592000, public"
 </filesmatch>
 <filesmatch "\\.(css)$">
  Header set Cache-Control "max-age=604800, public"
 </filesmatch>
 <filesmatch "\\.(js)$">
  Header set Cache-Control "max-age=216000, private"
 </filesmatch>
 <FilesMatch "\.(php)$">
    ExpiresActive Off
    Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    Header set Pragma "no-cache"
</FilesMatch>
</ifmodule>

如果我正在运行一个 php 文件,该文件正在返回一个值并保存某事。在 MySQL 数据库中,我必须重新加载两次或三次,直到一切正常。

我也在指定的文件上尝试了以下操作但没有成功(如此处所述如何防止 Apache httpd (MAMP) 中的 http 文件缓存

<files folder/file.php>
 <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
 </ifModule>
</files>

如果我将 no-cache 放在文件夹 htaccess 中,则相同

4

2 回答 2

1

为了防止 php 文件被缓存,请尝试删除ExpiresByType application/xhtml-xml用于 PHP 的 .

恕我直言,您也可以删除FilesMatchPHP 文件。

于 2014-06-25T12:16:59.007 回答
0

正如您已经确定的那样,两条“ExpiresByType”行可能是导致此问题的原因。

您的 .php 文件返回 text/html 或 application/xhtml-xml 类型的文档。因此,由 FilesMatch *.php 设置的标题与之前的条目相矛盾。然后选择哪一个?我不知道。

通常,PHP 文件执行的结果应该很少被缓存。

于 2014-06-25T12:12:31.440 回答