本文介绍了随机机会的无关重定向使用什么HTTP响应状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有1%的随机机会将访问者重定向到此YouTube视频.

My website has a 1% random chance of redirecting visitors to this YouTube video.

服务器当前发送的是旧版本302,但我希望它具有更好的语义.

The server currently sends the good-old 302, but I want it to have better semantics.

我不知道重定向是永久的还是临时的.从某种意义上说,这是永久性的,因为人们总是有1%的机会被重定向;从某种意义上来说,这是暂时的,因为人们不会每次都被重定向.

I don't know if the redirect is permanent or temporary. It's permanent in the sense that people always have a 1% chance of being redirected, and it's temporary in the sense that people don't get redirected every single time.

当前的3xx响应状态代码均不符合我网站的行为.

None of the current 3xx response status codes match my website's behavior.

此请求以及所有将来的请求"-不,不是所有将来的请求.

"This and all future requests" - nope, not all future requests.

这令人困惑.它确实指出"302已被303和307取代",所以我想这已经过时了但仍很常用?

This is confusing. It does state, "302 has been superseded by 303 and 307," so I guess this is obsolete yet still commonly used?

可以在另一个URI下找到对请求的响应"-Rickroll不是对原始请求的响应.它与我的网站无关! 当收到响应POST(或PUT/DELETE)的响应时,客户端应假定服务器已接收到数据,并应向给定URI发出新的GET请求." 303说明的最后一句话不适用于我的重定向.

"The response to the request can be found under another URI" - Rickroll is not the response to the original request. It has nothing to do with my site! "When received in response to a POST (or PUT/DELETE), the client should presume that the server has received the data and should issue a new GET request to the given URI." The last sentence of the 303 description doesn't work with my redirect.

在这种情况下,应使用另一个URI重复该请求;但是,以后的请求仍应使用原始URI."是的!这就是我的重定向. "...重新发出原始请求时,不允许更改请求方法.例如,应使用另一个POST请求重复POST请求.不幸的是,这不适用于我的重定向.即使用户提交表单(POST方法),我的网站也会随机对用户进行Rickroll.

"In this case, the request should be repeated with another URI; however, future requests should still use the original URI." Yes! This is what my redirect is. "...the request method is not allowed to be changed when reissuing the original request. For example, a POST request should be repeated using another POST request." Unfortunately, this doesn't work with my redirect. My site randomly Rickrolls users even when they submit forms (POST method).

308与301存在相同的问题,因为并非将来所有请求都应发送到Rickroll视频.此外,不允许更改方法.

308 has the same issue as 301 because not all future requests should go to the Rickroll video. Furthermore, the method isn't allowed to change.

我的服务器应为与我的实际站点无关的随机机会重定向发送什么HTTP响应状态代码?

What HTTP response status code should my server send for random-chance redirects that have nothing to do with my actual site?

推荐答案

HTTP响应状态代码的官方来源是 RFC7231 ,而不是Wikipedia.您应该仔细阅读 RFC7231第6.4节以了解3XX状态代码.

The official source for HTTP response status codes is RFC7231, not Wikipedia.You should peruse RFC7231 Section 6.4 for the explanation of 3XX status codes.

通过随机机会重定向访问者"与实际的重定向无关,因此,符合您要求的状态代码为303,在第6.4.4节中对此进行了说明(重点是我的):

The "redirecting visitors by random chance" thing is irrelevant to the actual redirection,therefore the status code that fits your requirement is 303,which is explained in Section 6.4.4 as follows (emphasis mine):

303符合您的要求的三个原因:

303 fits your requirement for three reasons:

  1. 到其他资源":访问者被重定向到的资源与他们最初请求的资源不同.
  2. 执行检索请求":使用GET或HEAD请求获取最终资源.
  3. 不视为等效":原始请求URI不能用新URI替换,因为它不等效,换句话说,它是临时的.

为什么不是302?由于第6.4.3节中的这一部分解释(重点是我的):

Why not 302?Because of this part of the explanation in Section 6.4.3 (emphasis mine):

换句话说,用户代理可以使用相同的请求方法或不同的请求方法.规格允许302的灵活性不符合您的要求.

In other words, the user agent can use either the same request method or a different request method.The flexibility that the specification allows for 302 doesn't fit your requirement.

这篇关于随机机会的无关重定向使用什么HTTP响应状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:31
查看更多