3

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.

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

according to the documentations "error_page 404 = /err/error.php?error=404;" does not set a status code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.