Index fallback?

Edho Arief me at
Mon Oct 10 03:56:57 UTC 2016

I somehow can't make this scenario work:

root structure:
/b/ <-- no index.html

1. -> redirect to -> show /a/index.html
2. -> redirect to -> show @fallback


try_files $uri $uri/index.html @fallback;

doesn't work quite well because #1 becomes this instead:

1. -> show /a/index.html

and breaks relative path javascript/css files (because it's `/a` in
browser, not `/a/`).

And using

try_files $uri @fallback;

Just always show @fallback for both scenarios.


try_files $uri $uri/ @fallback;

Always return 403 for #2 because the directory exists and there's no

As a side note,

error_page 404 = @fallback;

Wouldn't work because as mentioned in the previous one, it returns 403
for #2 (directory exists, no index), not 404.

Is there any way to do it without specifying separate location for each
of them?

More information about the nginx mailing list