【问题标题】:Properly dealing with custom 404 pages正确处理自定义 404 页面
【发布时间】:2011-11-12 08:49:46
【问题描述】:

我有 3 个文件:index.php,.htaccess,404.shtml

index.php 包含:

<?php
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 
?>

.htaccess 包含:

错误文档 404 /404.shtml

404.shtml 包含:

你好世界

当我访问 index.php 时,我的浏览器告诉我 oops something went wrong. 可能出了什么问题?

【问题讨论】:

    标签: php .htaccess http-status-code-404


    【解决方案1】:

    我认为是因为 .htaccess 先出现,并且只有在物理文件确实不存在时服务器才会重定向到它。

    如果您通过 php 标头处理 404,您应该为真实用户处理它,例如。与

     <?
     header("Location: /this/page/really/not_exists.404"); //  trigger "real" 404
     //or
     header("Location: /404.shtml");
    

    作为参考,试试看这里 Why won't my PHP app send a 404 error?

    【讨论】:

      猜你喜欢
      • 2019-08-08
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 2010-11-04
      • 2012-10-26
      相关资源
      最近更新 更多