dongliuzi3410 2011-05-06 16:12
浏览 12
已采纳

PHP标头404无法正常工作

Why is this not working, as in the pre-set 404 page is not loaded:

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

.htaccess has the ErrorDocument 404 /404.html directive set.

Thank you.

  • 写回答

3条回答 默认 最新

  • dongzhi6087 2011-05-06 16:24
    关注

    Make sure your customized error page /404.html has the content size greater than 512 bytes. Many browsers like IE, Chrome etc don't show your customized page if content length of your custom 404 page is less than 512.

    UPDATE

    Based on your comments here is what I think is happening.

    If you look at the access.log or http headers in Firebug/HTTP Watch etc of this blank page, you'd see a 404 return code. Once the web server starts processing the PHP page, it's already passed the point where it would handle 404 handling by itself since your php file is actually FOUND. Now since your php code is merely returning status 404 without any content therefore a blank page gets displayed.

    Now since this is correct apache behavior and its up to you to create the contents for the 404 page. Something like this in your above php code will be fine I think:

    <?php
    header("HTTP/1.0 404 Not Found");
    exit("<h1>Not Found</h1>
    The requested URL " . $_SERVER["REQUEST_URI"] . " was not found on this server.
    <hr>");
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100