dpxyfa4718 2013-07-13 16:06
浏览 56

正确的错误类型软404

I try to correct error "soft404"

I read this https://support.google.com/webmasters/answer/181708?hl=fr so it's ok i understand.

To correct this error with a personalized page 404 can I do :

<?php



    try{
         echo "Error, I fail to load the services I catch It ! (have imagination)";
    }
    catch(Exception $e){
        header("HTTP/1.0 404 Not Found");
        include 'page404.html';
        exit;
    }


?>
  • 写回答

1条回答 默认 最新

  • dpvp56187 2013-07-13 16:12
    关注

    You don't quite understand the meaning of 404 error and confuse it with a 500 one.
    A PDO error has nothing to do with page existence. It is a code error means site experiencing temporary problems. Thus, 500 has to be sent.

    It is said that modern PHP versions have to take care of it, but I have some reports that it doesn't. The only guaranteed way known to me is to use php-fpm, as sending 503 in case of error is one its core features.

    Anyway, at least try to set display_errors = off in PHP settings (ini or perdir).
    Then change your code to.

    <?php
    echo "Je me connecte a un module foireux et la page est introuvable.";
    $pdo = new PDO("n'importe quoi !");
    

    and properly configured PHP will respond with 500 automatically!

    Yet if there is no page found - you indeed have to respond with 404.

    <?php
    $data = DB::getData("SELECT * FROM articles WHERE id=?", $_GET['id']);
    if (!$data)
    {
        throw new http404();
    }
    

    where http404() is a custom exception that have to be processed by a global exception handler. It have to send a 404 response. Just a

    header("HTTP/1.0 404 Not Found");
    exit;
    

    would be enough for Google.

    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算