我最近在我的网站上启动了一些caching控制,似乎有些function因此而停止工作。 我的PHP内容不再更新。 在Chromenetworking工具中,我可以看到一些PHP脚本请求大小(来自caching)。 我尝试刷新页面,但它仍然没有更新。 只有当我从Chrome中删除整个caching数据时才会更新。 我试图删除我在.htaccess中做了什么,但它并没有更新。 我如何声明PHP脚本不应该保存在caching中? 目前,JavaScript文件使用ajax和GET方法来更新一些不再更新的HTML文本。
我的.htaccess:
AddDefaultCharset UTF-8 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php ## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 month" # Media: images, video, audio ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType video/ogg "access plus 1 year" ExpiresByType audio/ogg "access plus 1 year" ExpiresByType audio/mp3 "access plus 1 year" ExpiresByType video/mp4 "access plus 1 year" ExpiresByType video/webm "access plus 1 year" ExpiresByType application/pdf "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" ExpiresByType image/x-icon "access plus 1 year" ExpiresByType text/html "access plus 2 days" # CSS and JavaScript ExpiresByType text/css "access plus 1 month" ExpiresByType application/javascript "access plus 1 year" ExpiresByType text/javascript "access plus 1 year" # Webfonts ExpiresByType font/truetype "access plus 1 year" ExpiresByType font/opentype "access plus 1 year" ExpiresByType application/x-font-woff "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType application/vnd.ms-fontobject "access plus 1 year" </IfModule> ## EXPIRES CACHING ## <FilesMatch ".(js|css|html|htm|php|xml)$"> SetOutputFilter DEFLATE </FilesMatch>
这是以前的情况(当一切正常时): 
现在是这样: 
这是我的cachingconfiguration谁工作得很好:
# MOD_DEFLATE COMPRESSION SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application$ # DEFLATE NOT COMPATIBLE BROWERS BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # NOT CHACHING IF ALREADY CACHED SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip # EXPIRE HEADERS <IfModule mod_expires.c> ExpiresActive On #Images ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" AddType image/x-icon .ico ExpiresByType image/ico "access plus 1 year" ExpiresByType image/icon "access plus 1 year" ExpiresByType image/x-icon "access plus 1 year" #Elements ExpiresByType application/xhtml+xml "access plus 1 week" ExpiresByType text/html "access plus 1 week" ExpiresByType text/css "access plus 1 week" ExpiresByType application/javascript "access plus 1 week" ExpiresByType text/x-javascript "access plus 1 week" #Others ExpiresDefault "access plus 1 month" </IfModule> # CACHE-CONTROL HEADERS <IfModule mod_headers.c> <FilesMatch "\\.(ico|jpe?g|png|gif|swf|gz|ttf)$"> Header set Cache-Control "max-age=2797200, public" </FilesMatch> <FilesMatch "\\.(css)$"> Header set Cache-Control "max-age=2797200, public" </FilesMatch> <FilesMatch "\\.(js)$"> Header set Cache-Control "max-age=2797200, private" </FilesMatch> <filesMatch "\\.(html|htm)$"> Header set Cache-Control "max-age=86400, public" </filesMatch> # Disable caching for scripts and other dynamic files <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> Header unset Cache-Control </FilesMatch> </IfModule>
除了dynamic内容之外,全部被caching和压缩。
基于http://www.seomix.fr/guide-htaccess-performances-et-temps-de-chargement/
强制PHP头你可以做到这一点
<FilesMatch "\.php$"> Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires "Sat, 2 Aug 1980 15:15:00 GMT" ExpiresActive On ExpiresDefault "access plus 0 seconds" </FilesMatch>