简体   繁体   English

使用301或303将http重定向到https

[英]Use 301 or 303 to redirect http to https

I'm not sure which is the best to use for my site when redirecting from http to https. 从http重定向到https时,我不确定哪个网站最适合我的网站使用。 At the moment I am using IIS rewrite rules to do the redirect. 目前我正在使用IIS重写规则来进行重定向。 The guides I've read on how to do this use either a 301 or a 303. And after reading up on 301 and 303, I'm still not sure which is best to use. 我读过关于如何使用301或303的指南。在阅读301和303之后,我仍然不确定哪个最好用。

My understanding is they are pretty much similar in what they do in regards to a redirect between http and https. 我的理解是它们与http和https之间的重定向非常相似。

Is there any difference and will it affect SEO in any way using one over the other? 有什么区别,它会以任何方式影响搜索引擎优化吗?

From the spec: 301 从规格:301

The 301 (Moved Permanently) status code indicates that the target 301(永久移动)状态代码表示目标
resource has been assigned a new permanent URI and any future 资源已被分配一个新的永久URI和任何未来
references to this resource ought to use one of the enclosed URIs. 对此资源的引用应该使用其中一个附带的URI。
Clients with link-editing capabilities ought to automatically re-link references to the effective request URI to one or more of the new 具有链接编辑功能的客户端应该自动将对有效请求URI的引用重新链接到一个或多个新的
references sent by the server, where possible. 尽可能由服务器发送的引用。

The server SHOULD generate a Location header field in the response containing a preferred URI reference for the new permanent URI. 服务器应该在响应中生成一个Location头字段,其中包含新永久URI的首选URI引用。 The
user agent MAY use the Location field value for automatic 用户代理可以使用Location字段值进行自动
redirection. 重定向。 The server's response payload usually contains a short 服务器的响应有效负载通常包含一个短消息
hypertext note with a hyperlink to the new URI(s). 超文本注释,带有指向新URI的超链接。

  Note: For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead. 

A 301 response is cacheable by default; 默认情况下,301响应可缓存; ie, unless otherwise 即,除非另有说明
indicated by the method definition or explicit cache controls 由方法定义或显式缓存控件指示

303 303

The 303 (See Other) status code indicates that the server is 303(请参阅其他)状态代码表示服务器是
redirecting the user agent to a different resource, as indicated by a URI in the Location header field, which is intended to provide an 将用户代理重定向到不同的资源,如Location头字段中的URI所示,该URI旨在提供
indirect response to the original request. 对原始请求的间接响应。 A user agent can perform 用户代理可以执行
a retrieval request targeting that URI (a GET or HEAD request if 针对该URI的检索请求(如果是,则为GET或HEAD请求)
using HTTP), which might also be redirected, and present the eventual result as an answer to the original request. 使用HTTP),它也可能被重定向,并将最终结果作为原始请求的答案。 Note that the new URI 请注意新的URI
in the Location header field is not considered equivalent to the 在Location头字段中不被认为是等效的
effective request URI. 有效的请求URI。

This status code is applicable to any HTTP method. 此状态代码适用于任何HTTP方法。 It is primarily used to allow the output of a POST action to redirect the user agent 它主要用于允许输出POST操作以重定向用户代理
to a selected resource, since doing so provides the information 到选定的资源,因为这样做提供了信息
corresponding to the POST response in a form that can be separately 对应于POST响应的形式可以单独进行
identified, bookmarked, and cached, independent of the original 识别,加入书签和缓存,独立于原始文件
request. 请求。

A 303 response to a GET request indicates that the origin server does not have a representation of the target resource that can be 对GET请求的303响应指示源服务器不具有可以是的目标资源的表示
transferred by the server over HTTP. 由服务器通过HTTP传输。 However, the Location field 但是,位置字段
value refers to a resource that is descriptive of the target value是指描述目标的资源
resource, such that making a retrieval request on that other resource might result in a representation that is useful to recipients without implying that it represents the original target resource. 资源,使得对该另一资源进行检索请求可能导致对收件人有用的表示,而不暗示它表示原始目标资源。 Note that 注意
answers to the questions of what can be represented, what 回答可以代表什么,什么是什么的问题
representations are adequate, and what might be a useful description 表示是充分的,可能是有用的描述
are outside the scope of HTTP. 超出了HTTP的范围。

Except for responses to a HEAD request, the representation of a 303 response ought to contain a short hypertext note with a hyperlink to 除了对HEAD请求的响应之外,303响应的表示应该包含一个带有超链接的短超文本注释。
the same URI reference provided in the Location header field. Location头字段中提供的相同URI引用。

Google says: 谷歌说:

Redirect your users and search engines to the HTTPS page or resource with server-side 301 HTTP redirects. 使用服务器端301 HTTP重定向将您的用户和搜索引擎重定向到HTTPS页面或资源。

I recommend following Google's advice rather than trying to implement a 303 strategy. 我建议遵循Google的建议而不是尝试实施303策略。

Source: https://support.google.com/webmasters/answer/6073543?hl=en 来源: https//support.google.com/webmasters/answer/6073543?hl = zh-CN

When you redirect http to https, essentially you want to preserve the "link juice" from SEO perspective. 当您将http重定向到https时,基本上您希望从SEO角度保留“链接汁”。

As you might know Google considers the number of backlinks a site has for ranking. 您可能知道Google会考虑网站排名的反向链接数量。

The main difference between the 301 and 303 redirect is essentially whether it passes link juice or not. 301和303重定向之间的主要区别主要在于它是否通过链接汁。 There are technical differences like what you mentioned but from SEO perspective, 301 is a better choice. 像你提到的技术差异,但从SEO的角度来看,301是一个更好的选择。

Here is a blog post that shows how 303 might affect SEO of your site. 这是一篇博文,展示了303如何影响您网站的SEO。 https://digitalreadymarketing.com/303-redirect-effect-seo/ https://digitalreadymarketing.com/303-redirect-effect-seo/

In case you are interested in learning more about duplicate content (http and https is a typical duplicate content issue), check this post. 如果您有兴趣了解有关重复内容的更多信息(http和https是典型的重复内容问题),请查看此帖子。 https://digitalreadymarketing.com/what-is-duplicate-content-how-to-find-solve-them/ https://digitalreadymarketing.com/what-is-duplicate-content-how-to-find-solve-them/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM