【问题标题】:Php error log 404 and redirect to home pagephp错误日志404并重定向到主页
【发布时间】:2016-11-17 23:46:33
【问题描述】:

我在下面有处理 404 错误的代码,但我喜欢将所有 404 错误重定向到主页,这就是我所拥有的:

function show_404($page = '', $log_error = TRUE)
{
    $heading = "404 Page Not Found";
    $message = "The page you requested was not found.";

    // By default we log this, but allow a dev to skip it
    if ($log_error)
    {
        log_message('error', '404 Page Not Found --> '.$page);
    }

    echo $this->show_error($heading, $message, 'error_404', 404);
    exit;
}

我怎样才能重定向到主页而不是给出 404 错误。

【问题讨论】:

  • 重定向到首页,然后显示实际错误?
  • header("location: index.php") ,您想知道如何重定向吗?
  • Php header redirect的可能重复
  • 上面的代码是我目前的,我只是想重定向到主页,仅此而已。
  • @user2969009,正如 Sam 所说的 header("location: index.php")。你试过了吗?

标签: php redirect http-status-code-404


【解决方案1】:

NOT 为不存在的资源返回除 404 状态之外的任何内容。搜索引擎爬虫和其他自动化实用程序充其量只能正常运行,最坏的情况是 DoS 您的网站离线。

唯一认为从 404 响应发出重定向被认为是可接受的情况是实际用户使用实际浏览器的情况,在这种情况下,您可以使用 <meta>在不破坏 HTTP 的情况下重定向以达到相同的效果。

例如:

<meta http-equiv="refresh" content="0;URL='/index.php'" />

只需在 &lt;head&gt; 部分提供一个包含指令的轻量级页面,您将 100% 避免我预测的厄运和忧郁。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 2016-01-06
    • 2010-12-06
    • 2023-03-10
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    相关资源
    最近更新 更多