php站长工具seo 404错误

php seo 404 error in webmaster tool

我有一个 PHP 站点,其中包含 1000 多个页面... 每天我都会删除 10 多页已经被 GOOGLE 索引的页面...

当访问者访问这些页面之一时,我会检查它是否已被删除...... 如果删除,我会将用户重定向到搜索页面以开始搜索类似内容... 我正在使用此代码:

if($deleted = true){
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /products-search.php");
    exit(); 
}

在 GOOGLE 网站管理员工具中,我遇到了很多此类页面的软 404 错误。 消息说:目标 URL 不存在,但您的服务器没有返回 404(找不到文件)错误。了解更多

我不想让用户收到 404 错误....我需要他去搜索页面...

如何解决这个问题?

您仍然应该 return 一个 404,除非您希望稍后恢复该页面。在这种情况下,重定向对于 SEO 来说是个坏主意。

你可以做的是 return header 中的 404,但无论如何都要显示搜索页面:

<?php

header("HTTP/1.1 404 Not Found");

echo "The page you're looking for doesn't exist or was deleted. You can use the search below to find more...";

// include search box here