404 重定向或更好的选择
404 Redirect or better option
我的 htaccess 文件中有以下代码来处理 404 代码:
ErrorDocument 404 https://www.mywebsite.co.uk/lost.php
RewriteEngine On
当然会返回自定义 404 页面(工作正常)。
我做了一个 nibbler 检查,结果如下:
It is a common mistake to setup missing page handling by using a
redirect. The missing page should directly return a 404 error and not
redirect to another page.
This website does not return a 404 error HTTP status code for missing
pages. This is bad because search engines like Google might mistake
this for a real page of content.
如果以上方法都不好,处理 404 错误代码的最佳做法是什么?我只是想要一些通用的东西。不需要使用 301,因为我的 404 的目的只是让访问者知道他们要找的东西不存在或者他们打错了。
如果 "common mistake" 要使用重定向应该怎么做?
感谢您的帮助。
视情况而定。如果您在 Web 服务器上有一个应用程序 运行,它接收每个 URL 进入并实现了一些逻辑,它自己必须弄清楚 URL 是否存在,那么应用程序应该直接 return 给定 URL 下的 404 错误页面,而不是重定向到另一个页面,如 404.html 左右。但是,如果您的网络服务器使用 .htaccess 文件处理 url 请求,那么在 URL.
无效的情况下,可以设置 returned 的文档
您需要从 404 处理程序中删除 https://
或 http://
否则它会强制 Apache 进行完全重定向而不是内部重写。
所以你可以使用:
ErrorDocument 404 /lost.php
我的 htaccess 文件中有以下代码来处理 404 代码:
ErrorDocument 404 https://www.mywebsite.co.uk/lost.php
RewriteEngine On
当然会返回自定义 404 页面(工作正常)。
我做了一个 nibbler 检查,结果如下:
It is a common mistake to setup missing page handling by using a redirect. The missing page should directly return a 404 error and not redirect to another page.
This website does not return a 404 error HTTP status code for missing pages. This is bad because search engines like Google might mistake this for a real page of content.
如果以上方法都不好,处理 404 错误代码的最佳做法是什么?我只是想要一些通用的东西。不需要使用 301,因为我的 404 的目的只是让访问者知道他们要找的东西不存在或者他们打错了。
如果 "common mistake" 要使用重定向应该怎么做?
感谢您的帮助。
视情况而定。如果您在 Web 服务器上有一个应用程序 运行,它接收每个 URL 进入并实现了一些逻辑,它自己必须弄清楚 URL 是否存在,那么应用程序应该直接 return 给定 URL 下的 404 错误页面,而不是重定向到另一个页面,如 404.html 左右。但是,如果您的网络服务器使用 .htaccess 文件处理 url 请求,那么在 URL.
无效的情况下,可以设置 returned 的文档您需要从 404 处理程序中删除 https://
或 http://
否则它会强制 Apache 进行完全重定向而不是内部重写。
所以你可以使用:
ErrorDocument 404 /lost.php