【问题标题】:Nginx custom PHP error_pages with different header status codes and body contentsNginx 自定义 PHP error_pages 具有不同的标头状态代码和正文内容
【发布时间】:2011-06-16 01:14:36
【问题描述】:

使用 Nginx 0.8.54 :我设置 PHP 错误页面对某些链接进行重定向,对其他链接进行 404 重定向,并显示自定义 HTML 正文。 nginx

server {
 error_page 404 = /err/error.php?error=404;
}

error.php

<?php
if( $_SERVER['REQUEST_URI'] == "/blah" ){
    header('Status: 301 Moved Permanently');
    header('location: http://localhost/ ');
}else
    header('Status: 404 Not Found');

echo 'This is a custom Error Page';
?>

Nginx 进行重定向没有问题,但对于 404 自定义页面,Nginx 发送 404 标头并显示默认 Nginx 页面而不是“这是自定义错误页面”文本。

【问题讨论】:

    标签: php error-handling nginx


    【解决方案1】:

    您是否尝试过不设置header('Status: 404 Not Found'); 两次? (例如,这已经是 404 错误页面)

    【讨论】:

    • 根据文档“error_page 404 = /err/error.php?error=404;”没有设置状态码
    猜你喜欢
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多