Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 404 file and it is working with nginx. However when I modify the 404 file to redirect the user it does not redirect.

visiting http://site.com/404.php redirects the user.

visiting http://site.com/askllj299lakj is just a blank page.

The code in the 404 file is just a header redirect,

header('Location: http://site.com/');

Why doesn't this work in nginx?

share|improve this question
Try removing the php from the 404.php file add some basic text, then visit http://site.com/askllj299lakj and see if you can view the text. If yes, then try using php echo to display the same text and see if that works. Are you using PHP FastCGI – Anagio Jun 8 '12 at 9:29
And look in your PHP error log. A space before the first <?php would cause these symptoms and would leave messages about it in your error logs. – Ladadadada Jun 8 '12 at 22:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.