301使用htaccess和缓存重定向:如何删除旧缓存?

发布于 2024-08-10 14:38:10 字数 331 浏览 7 评论 0原文

因此,经过大量帮助和研究,我终于能够通过 .htaccess 文件实现 301 重定向,但我注意到,除非我实际上在浏览器上点击“刷新”,否则由于仅读取缓存的网站,它不会重定向页面。

我尝试关闭所有浏览器,插入 .htaccess 文件,然后打开一个新浏览器,但它仍然打开缓存的网站。我大胆猜测,大多数客户都不会费心刷新页面,如果他们不这样做,则需要相当长的时间才能发现确实有一个新页面!

有什么想法吗?谢谢!

-Karl

编辑:我只是想在我们当前的主页上放置一个链接,上面写着“单击此处查看我们的新网站!”该链接将刷新页面,从而使 301 重定向生效。有人能想到这有什么负面影响吗?

So after much help and research I've FINALLY been able to get the 301 redirects working via .htaccess file, but I noticed that unless I actually hit 'refresh' on my browser it will not redirect the page due to simply reading the cached site.

I've tried closing all browsers, inserting the .htaccess file, and THEN opening a new browser, but it still opens the cached site. I would hazard a guess that most customers will not bother refreshing a page, and if they do not, this will take quite a while to discover that there is indeed a new page!

Any ideas? Thanks!

-Karl

EDIT: I just had the idea of putting a link on our current homepage that says, "Click here to see our new website!" and the link will refresh the page, which will in turn kick the 301 redirect into action. Can anyone think of any negative side-effects of this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赏烟花じ飞满天 2024-08-17 14:38:11

Karl,

我发现检查缓存标头的最佳方法是 实时 HTTP 标头Firefox 添加

关于您的主页,这是这样说的:

HTTP/1.x 200 OK
Date: Fri, 06 Nov 2009 15:16:57 GMT
Server: Apache
Last-Modified: Mon, 12 Oct 2009 16:52:05 GMT
Etag: "85dcc1-1386-4ad35eb5"
Accept-Ranges: bytes
Content-Length: 4998
Keep-Alive: timeout=10, max=99
Connection: Keep-Alive
Content-Type: text/html

如上所述,etag 是问题所在。快速(unixy)修复可能是: find /var/www/htdocs -type f|xargs touch 这将更改 www 目录中每个文件的修改时间。

但是,它确实取决于您的 apache 实例如何配置来生成 etag 值。这是关于使用 Apache 设置缓存的精彩小指南

至于您添加链接的建议,我认为这不会起作用。您无法强制浏览器远程刷新页面,并且如上所述,问题出在 etag 上,您的解决方案不会改变它。

Karl,

The best way I've found to examine caching headers is the Live HTTP Headers firefox add on.

This is what it says about your homepage:

HTTP/1.x 200 OK
Date: Fri, 06 Nov 2009 15:16:57 GMT
Server: Apache
Last-Modified: Mon, 12 Oct 2009 16:52:05 GMT
Etag: "85dcc1-1386-4ad35eb5"
Accept-Ranges: bytes
Content-Length: 4998
Keep-Alive: timeout=10, max=99
Connection: Keep-Alive
Content-Type: text/html

As mentioned above, the etag is the issue. A quick (unixy) fix might be: find /var/www/htdocs -type f|xargs touch which will change the modified time of every file in your www directory.

It does, however, depend on how your apache instance is configured to generate the etag value. Here's a great little howto on setting up caching with Apache.

As far as your suggestion to add a link, I don't think that will work. You can't force a browser to refresh a page remotely, and, as pointed out above, the issue is with the etags, which your solution won't change.

Dan

久随 2024-08-17 14:38:11

等一下。大多数用户的缓存将在几个小时内过期,除非您将服务器设置为使用异常长的缓存提示来提供页面。

如果您现在正在提供页面,则可以设置标头,以便客户端不会缓存它。请参阅此问题:

告诉浏览器不要缓存的正确方法是什么?

Wait a while. Most users caches will expire in a period of hours, unless you set the server to serve the page with an unusually long cache hint.

If you're serving the page now, you can set headers so that the client does not cache it. See this question for that:

What is the proper way to tell the browser not to cache?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文