Welcome! Log In Create A New Profile

Advanced

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

Posted by gadelkareem 
Nginx custom PHP error_pages with different header status codes and body contents
January 26, 2011 01:24PM
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

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


error.php

[code]
<?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';
?>
[/code]


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.

--------------
http://gadelkareem.com/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 183
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready