404 problem

Edho P Arief edho at myconan.net
Mon Jul 11 11:02:34 MSD 2011


On Mon, Jul 11, 2011 at 1:15 PM, etrader <nginx-forum at nginx.us> wrote:
> I set error page as
> error_page 404 = 404.php;
> or
> error_page 404 = /404.php;
>
> in both cases, it will load 404.php when visiting a non-existent page in
> the main directory as domain.com/not-exist.html; but it will not work
> for domain.com/sub-dir/not-exist.html
>
> How I can set Nginx to redirect to 404.php when visiting any missing
> page?
>

assuming you put that error_page in `location / { ... }` and you have
another `location /sub-dir/ { ... }`, try moving error_page to `server
{ ... }`.

instead of:

    server {
      location / {
        error_page ...
        ...
      }
      location /sub-dir/ {
        ...
      }
      ..
    }

use:

    server {
      error_page ...
      location / {
        ...
      }
      location /sub-dir/ {
        ...
      }
      ..
    }



More information about the nginx mailing list