nginx - redirect subdirectories path to single (in

2019-09-16 05:14发布

问题:

How to redirect all the sub directory path to single index.html file?

here is what i want nginx configuration:

location /user/* {
    alias /home/vishant/devcenter/baetter-share1;
    index index.html;
}

this means if i hit /user OR /user/vishant OR /user/xyz/vishant it should render only index.html page.

The code i have written is not working but what i thought should be similar to this.

回答1:

location /user/ {
    root /home/vishant/devcenter/baetter-share1;
    try_files /index.html =404;
}

Documentation:

  • location
  • root
  • try_files