php redirect not working with Nginx – Education Career Blog

Simple problem:

I have conditions in php like so:

if (!$authorized)
   show_site_404();

or like so for that matter

if (!$logged_on)
    show_login_page();

These are obviously toll gates so that we don’t have trespassers into parts of the system where only a specific user or only those that are logged on should be able to go.

The code in both these cases simply loads another page than that which was intended by

require( MAINPATH . 'site-404.php' );
exit();

With Apache, this was never a problem. No settings needed.

With Nginx, it sends all such calls to the frontpage. It’s like it doesn’t accept an internal “re-direct” if you see what I mean.

Any help appreciated.

,

The problem with require as this would stop your script with an error message although with errors turned off you probably wouldn’t notice this as you run an exit(); to stop execution anyway.

Check the constant variable is including the files, try them in the same directory without mainpath constant.

Leave a Comment