我应该使用哪种类型的重定向到连接页面?

what type of redirect to a connection page should I use?

如果在使用我网站的一项服务之前需要对用户进行身份验证,我应该使用哪种类型的重定向将用户重定向到连接页面?

只是为了确保爬虫使用正确的数字来见证我是一个多么好的学生!

可用的重定向状态:

301 Moved Permanently

The 301 (Moved Permanently) status code indicates that the target resource has been assigned a new permanent URI.

302 Found

The 302 (Found) status code indicates that the target resource resides temporarily under a different URI.

303 See Other

The 303 (See Other) status code indicates that the server is redirecting the user agent to a different resource.

304 Not Modified

There is no need for the server to transfer a representation of the target resource because the request indicates that the client already has a valid representation.

307 Temporary Redirect

This status code is similar to 302 (Found), except that it does not allow changing the request method from POST to GET.

308 Permanent Redirect

This status code is similar to 301 (Moved Permanently), except that it does not allow changing the request method from POST to GET.

状态 305 Use Proxy and 306 (Unused) 分别已弃用且不再使用。

所以默认情况下,我会选择 303 See Other,因为它最适合您的需求。

如果用户需要登录才能查看 URL,您不应重定向他。

此 URL 应该使用表单发送 401 状态,让您的用户直接登录。然后 return 他的内容与 HTTP 200 相同 URL。

来自 HTTP specifications 的一些关于 401 的信息:

401 Unauthorized

The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information. HTTP access authentication is explained in "HTTP Authentication: Basic and Digest Access Authentication" [43].