重定向404或仅404标头 [英] Redirect 404 or just 404 header

查看:83
本文介绍了重定向404或仅404标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我应该添加header("HTTP/1.0 404 Not Found")而不进行重定向,还是应该重定向并添加404标头?

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

推荐答案

重定向的意思是您要的内容实际上在这里".

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

如果找不到,则找不到.不要重定向.

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

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

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.

(重定向的实际后果是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).

这篇关于重定向404或仅404标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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