301使用htaccess和缓存重定向:如何删除旧缓存?
因此,经过大量帮助和研究,我终于能够通过 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Karl,
我发现检查缓存标头的最佳方法是 实时 HTTP 标头Firefox 添加。
关于您的主页,这是这样说的:
如上所述,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:
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
等一下。大多数用户的缓存将在几个小时内过期,除非您将服务器设置为使用异常长的缓存提示来提供页面。
如果您现在正在提供页面,则可以设置标头,以便客户端不会缓存它。请参阅此问题:
告诉浏览器不要缓存的正确方法是什么?
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?