massive Issue with Caching and ModExpire on php Files

a 夏天 提交于 2020-01-11 13:48:19

问题


I do have a massive Issue with Caching and ModExpire on php Files if i'am using following in my global .htaccess

<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>

If i am running a php file, which is returning a value and saving sth. in a MySQL DB, i have to reload twice or three times until all is done right.

I also had tried the following on the specified file without success (as mentioned here How to prevent http file caching in Apache httpd (MAMP) )

<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>

same if i put no-cache inside the folders htaccess


回答1:


To prevent php files from caching try to remove ExpiresByType application/xhtml-xml, which is for PHP.

IMHO you can also remove FilesMatch for PHP files.




回答2:


The two "ExpiresByType" lines are probably the reason for this problem as you have already identified.

Your .php files return documents of type text/html or application/xhtml-xml. So the headers being set by FilesMatch *.php contradict the previous entries. Which one is then chosen? I don't know.

Generally, the results of PHP file execution should rarely be cached.



来源:https://stackoverflow.com/questions/24406037/massive-issue-with-caching-and-modexpire-on-php-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!