nginx : rewrite rule to remove /index.html from the $request_uri

前端 未结 7 659
[愿得一人]
[愿得一人] 2020-12-30 10:17

I\'ve seen a few ways to rewrite the $request_uri and add the index.html to it when that particular file exists in the file system, like so:

<
7条回答
  •  感动是毒
    2020-12-30 10:39

    For the root /index.html, the answer from Nicolas resulted in a redirect loop, so I had to search for other answers.

    This question was asked on the nginx forums and the answer there worked better. http://forum.nginx.org/read.php?2,217899,217915

    Use either

    location = / {
      try_files /index.html =404;
    }
    
    location = /index.html {
      internal;
      error_page 404 =301 $scheme://domain.com/;
    }
    

    or

    location = / {
      index index.html;
    }
    
    location = /index.html {
      internal;
      error_page 404 =301 $scheme://domain.com/;
    }
    

提交回复
热议问题