Index fallback?

Edho Arief me at myconan.net
Mon Oct 10 06:08:27 UTC 2016


Hi,

On Mon, Oct 10, 2016, at 12:56, Edho Arief wrote:
> I somehow can't make this scenario work:
> 
> root structure:
> /a/index.html
> /b/ <-- no index.html
> 
> accessing:
> 1. site.com/a -> redirect to site.com/a/ -> show /a/index.html
> 2. site.com/b -> redirect to site.com/b/ -> show @fallback
> 
> 

after trying out a bit more, this is the closest thing I can make which
works:

location / {
  error_page 418 = @dirlist;
  set $redirect 0;

  if (-d $request_filename) {
      set $redirect A;
  }

  if (-f $request_filename/index.html) {
      set $redirect "${redirect}B";
  }

  if ($uri !~ /$) {
      set $redirect "${redirect}C";
  }

  if ($redirect = ABC) {
      return 302 $uri/$is_args$args;
  }

  if ($redirect = A) {
      return 418;
  }
}

Honestly speaking, it looks terrible. It would help if someone can point
me to a better solution.



More information about the nginx mailing list