开发者

Nginx custom PHP error_pages with different header status codes and body contents

开发者 https://www.devze.com 2023-02-06 17:43 出处:网络
using Nginx 0.8.54 : I setup PHP error page to do redirections for some links and 404 for others and display custom HTML body.

using Nginx 0.8.54 : I setup PHP error page to do redirections for some links and 404 for others and display custom HTML body. 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 does the redirection with no problem but for the 404 custom page, Nginx sends the 404 headers and displays the default Nginx page instead of the 'This is a custom Error Page' text.


Have you tried not setting the header('Status: 404 Not Found'); twice ? (e.g. this is already a 404 error page)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号