为什么浏览器不在后退按钮历史记录中保留状态 302 页面?

Why do browsers not keep status 302 pages in back-button history?

当对 HTML 页面的请求响应 HTTP 302 Found(又名 'temporary redirect')时,FireFox 加载重定向页面 'in-place',而不保留最初打开的 URL U 在 'back-button history'.

302 的一个流行用法(我认为是对代码的正确使用)似乎是重定向到 /cookieAbsent 页面,提醒用户他们的浏览器没有 'support'(用户可能 禁用了 )cookie。

这种浏览器行为的后果是,如果用户决定启用 cookie,重新加载当然只是重新加载 (the server couldn't send you back, reliably, if it wanted to) /cookieAbsent 这不好,后退按钮返回到打开(无论是通过超链接还是键入)原始 U 之前他们所在的位置。这对我来说对 301 Moved Permanently(又名 'permanent redirect')有意义,但对 302 来说似乎是不可取的,尤其是像这样使用时。

如果我正在实现一个浏览器——或者,也许,希望报告现有浏览器中的错误或功能请求——这种行为是通用规范所要求的,还是仅由浏览器来执行觉得合适?

这是因为浏览器历史记录不(必须)符合缓存语义。

历史记录(后退按钮)的目标是向用户展示他们本应获得的页面(考虑到浏览器较早获得的(可能已过期的)响应)。

更详细的解释可以看:https://svn.tools.ietf.org/svn/wg/httpbis/draft-ietf-httpbis/latest/p6-cache.html#history.lists

You can find this very relevant bug from 20 years ago (!) on mozilla bugtracker

理由的简短总结似乎是他们这样做是因为一些网站显然错误地使用了 302 作为重定向路径

/product?limitedtimetoken 
302 to 
/product?superproduct 
302 to 
/superproduct 

有些人习惯了不保存的“错误”行为,并将其用于假装安全

/checkauth 
302 to 
/connected?gotoaccount 
302 to 
/account

虽然将这些保存在历史记录中是“技术上正确的”,但最终用户保存所有这些中等 URL 只是错误的行为,因为这些是假的 302,在现实中总是会重定向。

如果您曾经遇到过“我的浏览器的后退按钮不起作用,它总是后退前进”的情况,您有时会很容易理解他们的推理。

他们提到这也是 IE 和 Netscape 所做的,虽然我找不到这些的原因(但我认为它大部分是相同的:最终用户将所有这些保存在历史)。

by the way, it makes no sense to undo "this change" - this change is the right fix.. you're right that the site in question is doing the wrong thing, but we should still be fixing this problem.

this patch makes mozilla behave identically to Netscape 4x and IE w.r.t. storing redirect urls in global history. and it is important that we also implement this behavior because (unfortunately) many sites have grown up depending on it for some level of percieved security. this fact is something that can't be changed overnight, nor will it help the reputation of mozilla to not compromise on this issue.

假设 URL $u$ 重定向到 URL $v$。还假设 $u$ 被推送到历史记录,然后 $v$ 被推送到历史记录。当用户单击后退按钮时,用户将被带到 $u$,这将重定向到 $v$。用户会发现自己陷入无限循环,使后退按钮无用。