重定向或只是404头

时间:2021-01-12 15:22:57

I'm currently coding a site and I want to know the best alternative.

我目前正在编写一个网站,我想知道最好的选择。

Should I add header("HTTP/1.0 404 Not Found") without redirecting or should I redirect and add a 404 header?

我应该在不重定向的情况下添加header(“HTTP/1.0 404未找到”),还是应该重定向并添加404 header?

3 个解决方案

#1


10  

Redirecting means "What you asked for is actually over here".

重定向意味着“你所要求的实际上在这里”。

If it isn't found, then it isn't found. Don't redirect.

如果没有找到,那么就没有找到。不重定向。

Output a 404 status code, and then an HTML document that explains that whatever was requested wasn't found. You can then suggest an onwards journey by, for example, providing links to the main sections of the site or performing a search based on keywords extracted from the URL.

输出404状态代码,然后输出一个HTML文档,说明没有找到所请求的内容。然后,您可以通过提供指向站点主要部分的链接或基于从URL提取的关键字执行搜索来建议一个向前的旅程。

(The practical consequences of redirecting are that the URL vanishes from the address bar which makes it hard to look at an think "Oh, I mistyped that one letter, I'll just change it" or to copy/paste it into a bug report, etc).

(重定向的实际结果是URL从地址栏中消失,这使得我们很难看到这样的情况:“噢,我输入了一个字母,我将修改它”,或者将它复制/粘贴到bug报告中,等等)。

#2


5  

header("Status: 404 Not Found"); //FastCGI
include("404.php");
exit;

URI remains the user asked.

URI仍然是用户请求的。

#3


2  

You should redirect to an error page, but be sure you set status to 404. The error page can give the user tools to continue, like a sitemap, search, an explanation of what they were trying to load, and a little verbiage, like "We're sorry, but the page you requested at was not found."

您应该重定向到错误页面,但请确保将状态设置为404。错误页面可以让用户工具继续进行,比如站点地图、搜索、解释他们试图加载的内容,以及一些冗长的内容,比如“我们很抱歉,但是您请求的页面没有找到。”

Better yet, make your 404 page a script and use it to log the error so that you can become aware of common ones and fix them. It can be a tool for you too.

更好的是,将404页面变成一个脚本,并使用它来记录错误,这样您就可以了解常见错误并修复它们。它也可以成为你的工具。

#1


10  

Redirecting means "What you asked for is actually over here".

重定向意味着“你所要求的实际上在这里”。

If it isn't found, then it isn't found. Don't redirect.

如果没有找到,那么就没有找到。不重定向。

Output a 404 status code, and then an HTML document that explains that whatever was requested wasn't found. You can then suggest an onwards journey by, for example, providing links to the main sections of the site or performing a search based on keywords extracted from the URL.

输出404状态代码,然后输出一个HTML文档,说明没有找到所请求的内容。然后,您可以通过提供指向站点主要部分的链接或基于从URL提取的关键字执行搜索来建议一个向前的旅程。

(The practical consequences of redirecting are that the URL vanishes from the address bar which makes it hard to look at an think "Oh, I mistyped that one letter, I'll just change it" or to copy/paste it into a bug report, etc).

(重定向的实际结果是URL从地址栏中消失,这使得我们很难看到这样的情况:“噢,我输入了一个字母,我将修改它”,或者将它复制/粘贴到bug报告中,等等)。

#2


5  

header("Status: 404 Not Found"); //FastCGI
include("404.php");
exit;

URI remains the user asked.

URI仍然是用户请求的。

#3


2  

You should redirect to an error page, but be sure you set status to 404. The error page can give the user tools to continue, like a sitemap, search, an explanation of what they were trying to load, and a little verbiage, like "We're sorry, but the page you requested at was not found."

您应该重定向到错误页面,但请确保将状态设置为404。错误页面可以让用户工具继续进行,比如站点地图、搜索、解释他们试图加载的内容,以及一些冗长的内容,比如“我们很抱歉,但是您请求的页面没有找到。”

Better yet, make your 404 page a script and use it to log the error so that you can become aware of common ones and fix them. It can be a tool for you too.

更好的是,将404页面变成一个脚本,并使用它来记录错误,这样您就可以了解常见错误并修复它们。它也可以成为你的工具。

相关文章