PHP 中重定向/重新加载页面的最佳方法
在 PHP 中重新加载/重定向页面以完全删除所有历史记录/缓存的最佳方法是什么?我应该使用哪些标头?
发生了什么:
单击链接时,将设置获取参数并执行脚本。完成后,我想在没有获取参数的情况下重定向并重新加载页面。起初,看起来什么都没有发生,但是当按F5时,变化就出现了。
我想要的:
重定向并重新加载,以便无需按 F5 即可显示更改。
Whats the best way to reload/redirect a page in PHP which completely removes all history/cache? Which headers should I use?
What happens:
On clicking a link, get-parameters is set and a script is executed. When finished, I want to redirect and reload the page without the get-parameters. At first, it looks like nothing has happened, but when pressing F5, the changes appear.
What I want:
Redirect and reload so the changes appear without pressing F5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
参考:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10 .html
编辑:
Ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
edit:
重新加载页面并强制不从缓存中获取页面的最佳方法是将随机 ID 或时间戳作为查询字符串附加到 url 末尾。它使每次请求都是独一无二的。
The best way to reload a page and force it to be not taken from the cache will be to append a random id or timestamp to the end of the url as querystring. It makes the request unique each time.
试试这个:
这应该替换浏览器历史记录,但不替换缓存。
Try this:
This should replace browser history but not cache.
仅供参考,与 SEO 相关:
301 会告诉搜索引擎替换其索引中的 url。因此,如果 url1 使用 301 重定向到 url2,则所有主要搜索引擎 [google、yahoo + bing] 都会将 url1 替换为 url2。
302 的工作方式不同。它表示该网址
暂时
位于其他地址。查看这篇文章
just for information, related to SEO:
301 would tell search engine to replace url in their index. so if url1 is redirecting to url2 with 301, all major search engine [google, yahoo + bing] would replace url1 with url2.
302 works in different way. It says the url is located
temporarily
in some other address.see this post
最安全的方法是使用标头重定向,
但请注意,必须在将任何其他输出发送到浏览器之前发送它。
The safest way is to use a Header Redirect
But beware, that it has to be sent BEFORE any other output is sent to the browser.