可以返回HTTP 410而不是404吗?

huangapple go评论88阅读模式
英文:

Is it ok to return HTTP 410 instead of 404?

问题

I understand what is http code 410 (gone) vs 404 (not found) is. I am wondering if a page never existed (Wrong URI entered by the user), is it ok to return 410 instead of 404? I know 404 is what most sites would return in this case. Is there any harm in returning 410?

我理解HTTP状态码410(已消失)与404(未找到)的区别。我想知道如果页面从未存在过(用户输入了错误的URI),是否可以返回410而不是404?我知道在这种情况下,大多数网站会返回404。返回410是否会有什么问题?

英文:

I understand what is http code 410 (gone) vs 404 (not found) is. I am wondering if a page never existed (Wrong URI entered by the user), is it ok to return 410 instead of 404 ? I know 404 is what most sites would return in this case. Is there any harm in returning 410 ?

答案1

得分: 1

直接回答你的问题,这种情况下应该返回410状态码而不是404状态码不会对其造成'伤害'。

然而,对于从未存在过的资源返回410是误导的,不应该这样做。

状态码的整个目的是尽可能清楚地告诉用户它成功或失败的原因。通过发送410,用户可能会认为这个资源曾经存在,并尝试使用其他URL来访问它。在这种情况下使用404,用户将知道这个资源从一开始就不存在。

英文:

To answer your question directly, there should be no 'harm' to return a 410 status code instead of a 404 status code in this scenario.

However, returning a 410 for a ressource that never existed in the first place is misleading and should not be done.

The whole point of the status code is to be as clear as possible as to why it succeeded/failed for the user who receives it. By sending a 410, the user might think this ressource once existed and might try alternative URLs to access it. By using a 404 in this context, the user will know that this ressource never existed in the first place.

答案2

得分: 0

A 410状态代码意味着您有意删除了一个页面,您不希望它再出现。这告诉搜索引擎快速忘记该页面,不再费心查找它。404状态代码表示您找不到页面,但也许以后会出现。搜索引擎将继续检查该页面,以查看是否有变化。

如果您对从未存在过的页面使用410状态代码,您的服务器必须能够处理该代码,并且您必须确保将来永远不会创建该页面。否则,您可能会让搜索引擎和用户感到困惑,他们可能会想知道该页面发生了什么事情。对于从未存在过且永远不会存在的页面,404状态代码更合适。

来源链接:https://mysagaventure.com/404-vs-410-status-errors-whats-the-difference-and-how-to-fix-them/

英文:

A 410 status code means that you deleted a page on purpose and you don’t want it back. This tells search engines to forget about that page quickly and not to bother looking for it again. A 404 status code means that you can’t find a page, but maybe it will come back later. Search engines will keep checking that page to see if it changes.

If you use 410 status code for a page that was never there, your server has to be able to handle that code and you have to be sure that you will never create that page in the future. Otherwise, you might confuse search engines and users who might wonder what happened to that page. A 404 status code is better for pages that were never there and never will be.

https://mysagaventure.com/404-vs-410-status-errors-whats-the-difference-and-how-to-fix-them/

huangapple
  • 本文由 发表于 2023年7月5日 00:20:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定