2016-07-14 81 views
0

我有下面这段代码处理404错误,但我想重定向所有的404错误,主页,这里就是我:PHP的错误日志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错误。

+0

重定向到主页,然后显示实际的错误? – pmahomme

+0

'header(“location:index.php”)',你想知道如何重定向? –

+0

[Php header redirect]可能重复(http://stackoverflow.com/questions/4934357/php-header-redirect) –

回答

0

执行不是返回除了404状态以外的任何不存在的资源。搜索引擎抓取工具和其他自动化实用程序最多只能运行不正确,最糟糕的情况是您的网站会脱机。

情况,其中发出从404响应重定向将被认为是可以接受的是在与实际的浏览器的实际用户的情况下,并且在这种情况下可以使用一个<meta>重定向来达到同样的效果而不会破坏HTTP。

如:

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

就成为包含该指令的轻量级网页在<head>部分,你会避免我预测危困的100%。