我应该使用什么 HTTP 重定向状态来链接异地?

发布于 2024-08-08 21:42:11 字数 374 浏览 5 评论 0原文

当通过 Google 随机浏览我的网站时,我注意到它将远程重定向显示为本地文件。现在这可能是好事,也可能是坏事,但我想知道如何解决这个问题,以免发生这种情况?

我目前正在使用 PHP 和 header('Location: ... 发送 302 重定向。查看 HTTP 状态代码,我猜测我应该使用 303 重定向来重定向异地。有人可以在这里帮助我吗?确认/否认这一点,或者告诉我应该做什么?

显然,由于我无法告诉谷歌按照命令重新索引我的网站,所以自己测试这个存在问题......

While randomly browsing my website via Google, I noticed that it was showing up remote redirects as local files. Now this can be both good and bad, but I'm wondering how can I fix this so it doesn't happen?

I'm currently using PHP and header('Location: ... which sends a 302 redirect. Looking over the list of HTTP status codes, I'd take a guess that I should be using 303 redirects to redirect offsite. Is anyone able to help me here, and either confirm/deny this, or tell me what I should be doing instead?

Obviously, due to me not being able to tell Google to reindex my site on command, there's issues with being able to test this myself...

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

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

发布评论

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

评论(2

挖鼻大婶 2024-08-15 21:42:11

303 状态代码旨在用于POST 请求的响应重定向到不同的资源:

此方法的存在主要是为了允许 POST 激活的脚本的输出将用户代理重定向到选定的资源。

在您的情况下,您应该使用 301 状态代码对于永久重定向:

已为所请求的资源分配了一个新的永久 URI,并且将来对此资源的任何引用都应使用返回的 URI 之一。

或者您使用临时重定向 (302/< a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8" rel="nofollow noreferrer">307)并告诉搜索引擎不要索引该内容文件。

The 303 status code is intended to be used in response of a POST request to redirect to a different resource:

This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.

In your case you should use the 301 status code for a permanent redirect:

The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs.

Or you use a temporary redirect (302/307) and tell the search engines not to index that documents.

已下线请稍等 2024-08-15 21:42:11
Note: Many pre-HTTP/1.1 user agents do not understand the 303
status. When interoperability with such clients is a concern, the
302 status code may be used instead, since most user agents react
to a 302 response as described here for 303.

我不知道 HTTP/1.1 之前的用户代理有哪些,所以...
根据您的用途,我会使用 301(永久)或 307(临时)。 301 会告诉 Google 的行为就像您直接链接到重定向的网站一样。

303 看起来专门用于提交表单后的重定向。

编辑:

虽然你的问题是“我应该使用什么 HTTP 重定向状态来链接异地?” -- 直接异地链接怎么样? (我猜如果您使用表单进行链接,则此方法不起作用,在这种情况下您使用 303 状态代码)

Note: Many pre-HTTP/1.1 user agents do not understand the 303
status. When interoperability with such clients is a concern, the
302 status code may be used instead, since most user agents react
to a 302 response as described here for 303.

I don't know what pre-HTTP/1.1 user agents there are out there, so...
Depending on what you're going for, I'd use either 301 (permanent) or 307 (temporary). 301 will tell Google to behave as if you linked to the redirected site directly.

303 looks like it's intended for use in redirecting after submitting forms, specifically.

edit:

though your question is "What HTTP redirect status should I use to link offsite?" -- how about linking offsite directly? (which I guess doesn't work if you're using a form to do the linking, in which case you would use the 303 status code)

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