重定向到404网页或显示404消息?

问题描述:

我使用的是cms,文件未找到的错误可以通过不同的方式处理:

I am using a cms, and file-not-found errors can be handled in different ways:


  1. 重定向,但是错误消息将显示为内容(使用带有菜单/页脚的默认布局)。

  2. 页面将被重定向到error.php 1.但地址已更改)

  3. 该页面将重定向到现有页面,例如sitemap.php

是否有相对于搜索引擎优先的方法,或者没有区别?

Is there a method to be preferred in regards to search engines, or does this make no difference?

如果找不到,则应发出404页面。执行重定向会导致302代码,后面紧跟一个'200 OK',这意味着有一些内容。一个404单元格显示没有文件,停止bug我。

If it's not found, then you should issue a 404 page. Doing a redirect causes a 302 code, followed by a '200 OK', implying that there IS some content. A 404 flat out says "there is no file. stop bugging me".

这样的404页面会带有正确的标题代码:

Something like this would present a 404 page with proper header code:

<?php
if ($page_not_found) {
   header('This is not the page you are looking for', true, 404);
   include('your_404_page.php');
   exit();
}