gpt4 book ai didi

http - 我需要使用 http 重定向代码 302 还是 307?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:27:05 25 4
gpt4 key购买 nike

假设我的网站上有一个页面显示当月的媒体发布
http://www.mysite.com/mediareleases.aspx

并且出于进入*的平凡原因,必须为该页面提供一个包含当前日期的查询字符串,以便生成此列表:
http://www.mysite.com/mediareleases.aspx?prevDays=18

因此,我需要将请求 http://www.mysite.com/mediareleases.aspx 的客户端重定向到 http://www.mysite.com/mediareleases.aspx?prevDays =whateverDayOfTheMonthItIs

我的问题是,如果我希望 google 索引没有查询参数的页面,我应该使用状态码 302 还是 307 来执行重定向?

两者都表明该页面已“暂时”移动 - 这正是我想要的,因为如果您明白我的意思,该页面每天都会“移动”。

[*] 我正在使用闭源 .NET CMS 的一项功能,所以我的双手被束缚了。

最佳答案

Google's documentation似乎表明 302 和 307 都被同等对待,并且“Googlebot 将继续抓取原始位置并将其编入索引。”

但面对模棱两可的情况,您不妨深入研究 RFC 并尝试做正确的事,天真地希望爬虫也会做同样的事情。在这种情况下,RFC 2616 § 10.3包含每个响应代码几乎相同的定义,但有一个异常(exception):

302: Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.

307: Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.

这并没有给我留下显着的区别。我的解读是,302 指示客户网站管理员不可信任,而 307 明确告诉网站管理员客户不会信任他们,因此他们可以随意更改重定向。

我认为更能说明问题的是 302 定义中的注释:

Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client.

对我来说,这表明 302 和 307 在很大程度上是等价的,但是 HTTP/1.0 客户端第一次未能正确实现 302。

关于http - 我需要使用 http 重定向代码 302 还是 307?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2467664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com