处理各种类型的 URL 重定向

发布于 2024-09-17 23:44:54 字数 283 浏览 4 评论 0原文

通常,在编写 HTTP 客户端软件时,HTTP 协议为如何处理重定向的 URL 提供了足够的信息。具体来说,如果 HTTP 请求返回重定向代码 302 或 307,则应将重定向视为临时的,客户端应继续使用原始 URL。但是,重定向代码 301 表示客户端应丢弃旧 URL,并永久使用重定向的 URL。

但是对于不是由 HTTP 服务器本身发出的重定向,是否有任何标准做法?换句话说,HTML 或 Javascript 重定向?直觉上,我认为 HTML/Javascript 重定向应该像 301 一样处理,但我不确定这是否是一个好主意。

Generally, when writing HTTP client software, the HTTP protocol provides sufficient information for how to handle redirected URLs. Specifically, if an HTTP request returns a redirect code of 302 or 307, the redirect should be considered temporary and the client should continue to use the original URL. However, a redirect code of 301 indicates that the client should discard the old URL, and permanently use the redirected URL.

But is there any standard practice for redirects which are NOT issued by the HTTP server itself? In other words, HTML or Javascript redirects? Intuitively, I'd think that an HTML/Javascript-redirect should be handled like a 301, but I'm not sure if this is a good idea.

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

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

发布评论

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

评论(1

土豪我们做朋友吧 2024-09-24 23:44:54

HTML 或 JavaScript 中没有“重定向”,您所做的只是指示浏览器导航到另一个页面。将其视为相当于在地址栏中输入 URL。这里不存在暂时或永久的问题。

There are no "redirects" in HTML or JavaScript, all you do is instruct the browser to navigate to another page. Think of it as equivalent to entering a URL in your address bar. There is no question of temporary or permanent here.

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