我需要使用http重定向代码302或307吗? [英] Do I need to use http redirect code 302 or 307?

查看:169
本文介绍了我需要使用http重定向代码302或307吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的网站上有一个页面显示当月的媒体发布

http://www.mysite.com/mediareleases.aspx

Suppose I have a page on my website to show media releases for the current month
http://www.mysite.com/mediareleases.aspx

由于进入*平常的原因,必须为此页面提供一个包含当月当前日期的查询字符串才能生成此列表:

http://www.mysite.com/mediareleases.aspx?prevDays=18

And for reasons which it's mundane to go into*, this page MUST be given a query string with the current day of the month in order to produce this list:
http://www.mysite.com/mediareleases.aspx?prevDays=18

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

As such I need to redirect clients requesting http://www.mysite.com/mediareleases.aspx to http://www.mysite.com/mediareleases.aspx?prevDays=whateverDayOfTheMonthItIs

我的问题是,如果我想谷歌索引没有查询参数的页面,我应该使用状态代码302或307来执行重定向?

My question is, if I want google to index the page without the query parameter, should I use status code 302 or 307 to perform the redirect?

两者都表明该页面已暂时移动 - 这就是我想要的,因为如果你理解我的意思,页面每天都会移动。

Both indicate that the page has "temporarily" moved - which is what I want because the page "moves" every day if you get my meaning.

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

[*] I'm using a feature of a closed-source .NET CMS so my hands are tied.

推荐答案

Google的文档似乎表明302和307都被等同地对待,并且Googlebot将继续抓取并索引原始位置。

Google's documentation seems to indicate that both 302 and 307 are treated equivalently, and that "Googlebot will continue to crawl and index the original location."

但是面对模棱两可,你可能会深入研究RFC并尝试做正确的事情,天真的希望爬行者会做同样的事情。在这种情况下, RFC2616§10.3包含几乎相同的内容每个响应代码的定义,但有一个例外:

But in the face of ambiguity, you might as well dig into the RFCs and try to do the Right Thing, with the naïve hope that the crawlers will do the same. In this case, RFC 2616 § 10.3 contains nearly identical definitions for each response code, with one exception:


302:由于重定向可能有时会被修改,客户端应该继续使用Request-URI来处理将来的请求。

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

307:由于重定向 MAY 有时会被更改,客户端应该继续使用Request-URI来处理将来的请求。

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

哪个确实如此不要把我当作一个重要的区别。我的阅读是302指示客户网站管理员不值得信任,307明确告诉网站管理员客户不会信任他们,所以他们可以自由地改变重定向。

Which does not strike me as a significant distinction. My reading is that 302 instructs clients that webmasters are untrustworthy, and 307 explicitly tells webmasters that clients will not trust them, so they may freely alter the redirect.

我认为更有说服力的是302定义中的注释:

I think the more telling point is the note in 302's definition:


注意:RFC 1945和RFC 2068指定不允许客户端更改方法在重定向的请求上。但是,大多数现有的用户代理实现将302视为303响应,对Location字段值执行GET,而不管原始请求方法如何。已经为希望明确清楚客户预期会有何种反应的服务器添加了状态代码303和307.

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.

Which, to me, indicates that 302 and 307 are largely equivalent, but that HTTP/1.0 clients failed to implement 302 correctly the first time around.

这篇关于我需要使用http重定向代码302或307吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆