如何阻止浏览器使用旧的缓存index.html?

时间:2012-03-28 19:53:52

标签: apache caching mod-rewrite mod-expires

我正在重做整个网站,而浏览器正在使用位于同一网址的已缓存index.html个网页。

这是其中一个问题目录中.htaccess文件的全部内容:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /products/

    # Remove 'index.html' from the URL for old links that include it.
    RewriteCond %{THE_REQUEST} ^.*\index\.html?\ HTTP/
    RewriteRule ^(.*)index\.html?$ "/products/$1" [R=301,L]

    # Use index.php for all requests.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ /products/index.php [L]
</IfModule>

# An atempt to tell the browser not to use a cached .html file.
ExpiresActive on
ExpiresByType text/html "access plus 0 seconds"

<FilesMatch "\.(html)$">
    Header set Cache-Control "private, must-revalidate"
</FilesMatch>

我在这里尝试了很多东西,但没有任何效果。这就是我在标题中看到的所有内容:

Request URL:http://www.example.com/products/
Request Method:GET
Status Code:200 OK (from cache)

没有请求标头或响应标头。

我想我可以尝试使用RewriteRule来添加类似?28032012之类的内容,但我不知道如何尝试。

4 个答案:

答案 0 :(得分:0)

我读过追加?版本=&lt;%=版本%&gt;有问题的文件名是缓存破坏的好方法。您还可以尝试使用http标头“cache-control:max-age = 600”作为一种更简单的解决方案,以便从服务器中提取页面上10分钟或更早的内容。

答案 1 :(得分:0)

你可以追加/?到你的URL的末尾。 例如:

www.google.com/?

答案 2 :(得分:0)

我最终使用的解决方案是将所有www请求重定向到非www请求。基本上,这种方法阻止了任何浏览器使用任何缓存资源,因为网站的www版本不再存在。

答案 3 :(得分:0)

这对我有用。

<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
</IfModule>

参考:https://wp-mix.com/disable-caching-htaccess/