什么时候显示404和301? [英] When to show 404 versus 301?

查看:156
本文介绍了什么时候显示404和301?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直注意到Google在细读我们的网站方面出现了一些奇怪的结果.一个问题是这样的网址:

http://example.com/randomstring

正在显示google的所有数据

http://example.com/

所以在我看来,有两种解决方案.一种是在有人访问主URL的子URL时添加301重定向,然后将其重定向到父URL,或者仅给出404,并显示一条很好的消息,说:也许您是指 parent-url ".

有什么想法吗?我很确定自己知道要发送到哪里,但是正确的网络礼节是什么? 404或301?

解决方案

只要请求不存在的东西,正确的http方式就是404.

301用于移动了 的东西,在这里不是这种情况.

但是,如今很少遵循100%正确的http约定.根据上下文,将用户重定向到主页并显示一条通知,即未找到该页面且已将其重定向,这可能会很有用.尽管在这种情况下,您应该使用303 See Other代码.

不过,您应该从不重定向,但不要让用户知道发生了重定向.这使用户感到困惑,也许是错误的.

So I've been noticing some strange results in how google peruses our site. One issue is that a url such as this:

http://example.com/randomstring

is showing up on google with all of the data of

http://example.com/

So in my mind there are two solutions. One is to add a 301 redirect whenever someone visits a sub-url of the main one, and redirect them to the parent URL, or just give a 404, with a nice message saying, "Maybe you meant parent-url".

Thoughts? I'm pretty sure I know where I want to send them, but what is the proper web-etiquette? 404 or 301?

解决方案

The correct http way would be a 404, as long as a request is made to something that doesn't exist.

301 is for something that is moved, which is not the case here.

However, 100% correct http convention is rarely followed today. Depending on the context it could be useful to redirect the user to the home page with a notification that the page wasn't found and that they were redirected. Though in this case you should use a 303 See Other code.

You should never redirect without letting the user know that a redirect happened, though. That confuses the user to think that maybe something is wrong.

这篇关于什么时候显示404和301?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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