3

How to redirect to begins with "/admin" url redirect to /admin/index.html (single page app) and another pages redirect to /index.html (other single page app).

my nginx.conf is here

location / {
    if ( $allowed = "deny" ) { return 403; }
    try_files $uri /index.html;
}

location /admin {
    alias /usr/share/nginx/html/admin;
}

this is working but multi level url redirect to 503 error.

sample: get /admin/questions/1 ->fail 503

sample: get /admin/questions -> fail 503

sample get /admin -> ok

Mesut Yiğit
  • 649
  • 10
  • 21

1 Answers1

4

I solved it.

default.conf:

 root /usr/share/nginx/html;
 index index.html;

  location ~ ^/admin {       
    try_files $uri /admin/index.html;
  }

  location / {       
    try_files $uri /index.html;
  }
Mesut Yiğit
  • 649
  • 10
  • 21
  • Still I think it would work without regex, "location /admin/" should be enough. But anyway, if it works... – JosefScript Nov 01 '16 at 15:48
  • admin/index.html is a single page app. There are many route url in the page (html5 routing). If I call www.example.com/admin/questions/1/categories from server , it must return the just a admin/index.html . When client get this admin page, route to /questions/1/categories at client side. – Mesut Yiğit Nov 02 '16 at 08:51