Reputation: 61
Following my nginx rule:
error_page 404 /page.php;
Following the code of page.php:
<?php
echo 1;
header('location: ../page2.php');
?>
The output in case of 404 is 1
and the page doesn't redirect to page2.php, I had tried to remove echo 1;
but same output. How to solve?
Upvotes: 0
Views: 126
Reputation: 30565
If you turn PHP errors on or look in your error logs, your probably getting an error:
Warning: Cannot modify header information - headers already sent (output started at file:line)
Functions that send/modify HTTP headers must be called before any output to the browser is made.
Your echoing before the header function which is stopping the header function working i.e Your page isn't redirecting.
You'd be better of using your echo
to display the required 404 message to your user and then use another method to move the user to a different page (Javascript)
Upvotes: 3