【问题标题】:Include 404 Error Page包含 404 错误页面
【发布时间】:2015-10-18 16:45:20
【问题描述】:

我正在尝试在 IIS-8 中返回默认的 404 错误页面。我正在使用此代码:

// Return 404 in case no product was found
if($product_index == -1) {
    header('HTTP/1.0 404 Not Found');
    exit;
}

此代码以 404 错误响应,但页面只是空白。
有没有办法使用 PHP 包含默认的 404 错误页面?

【问题讨论】:

  • 您可以添加location 进入404页面:header('Location:404.html');
  • 是的,这可以工作,但我想让用户保持在同一页面上(而不是重定向,我会使用包含)。如何获取404错误页面文件路径?
  • 不清楚你在说什么?如果用户打开的页面根本不存在,那么他必须只被发送到 404 页面。

标签: php iis iis-8


【解决方案1】:

只需再次添加标题即可重定向到 404 页面,如下所示:

// Return 404 in case no product was found
if($product_index == -1) {
    header('HTTP/1.0 404 Not Found');
    header("Location: http://yoursite/404.php");
    exit;
}

如果你还是因为 IIS-8 遇到问题,可以关注Custom 404 error page not working on IIS 8.5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-13
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2016-05-31
    • 2017-12-17
    • 2014-05-15
    相关资源
    最近更新 更多