避免 301 重定向缓存
这是使用 301/303/307 重定向的后续问题对于动态短网址,我尝试确定当目标网址频繁更改时实现短网址重定向的最佳方法。
虽然 301 和 307 重定向似乎都以相同的方式执行,但我关心的问题是 301 重定向缓存(如文档所述 这里)-是避免这种情况的最佳方法,使用 307 重定向代替(我假设307 重定向永远不会缓存?),或者显式发送无缓存标头(“Cache-Control:无缓存,必须重新验证”)?
This is a follow up question to Using 301/303/307 redirects for dynamic short urls, where I try to determine the best method for implementing short url redirection when the destination url will change on a frequent basis.
While it seems that 301 and 307 redirects both perform the same way, the issue that concerns me is 301 redirect caching (as documented here)- is the best way to avoid this to use 307 redirects instead (I'm assuming 307 redirects will never cache?), or to explicitly send a no-cache header ("Cache-Control: no-cache, must-revalidate")?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要试图避免 301 缓存。如果您不希望任何用户代理缓存您的重定向,那么就不要使用 301 重定向。换句话说,301 缓存将继续存在,从语义上讲,它是一个永久重定向,因此,如果您计划更改目标 URL,301 不是正确使用的状态代码。另一方面,默认情况下不缓存 307 响应。
Don't try to avoid 301 caching. If you don't want any user agent to cache your redirect, then simply don't use a 301 redirect. In other words, 301 caching is here to stay, and semantically, it's a permanent redirect, so if you're planning to change the destination URL, 301 is not the right status code to use. On the other hand, 307 responses are not cached by default.
在您想要 301 重定向带来的行为的情况下,例如浏览器书签的更新和 google bot 中 URL 的更改,但同时想要跟踪重定向或执行某些其他类型的功能,您可以随时添加将控制标头缓存为“无缓存”
在 php 中,它看起来像这样:
相关:
https://stackoverflow.com/a/19003320/175071
In situations where you want the behaviour that a 301 redirect brings, like the updating of browser bookmarks and the change of URL in google bot, but at the same time want to track the redirects or perform some other kind of functionality you can always add the cache control headers to "no cache"
In php it looks like this:
Related:
https://stackoverflow.com/a/19003320/175071