Nginx not redirect all requests to index.html

I am trying to redirect all requests to index.html on Nginx but it's not redirecting.

Working -> https://www.example.com/reviews

Not Working -> https://www.example.com/reviews/

in 2nd URL if you see in last due to "/" Slash it's not working.

I am using the following settings in Nginx settings

location / {
  try_files $uri /index.html;
}

1 answer

  • answered 2020-08-09 17:37 Coder-256

    Nginx considers directories (URLs with a trailing slash) separately from normal files. Try this instead:

    location / {
      try_files $uri $uri/ /index.html;
    }