Rewriting nginx for pushState-URL's

后端 未结 5 2020
再見小時候
再見小時候 2020-12-04 11:27

I am trying to get nginx to work with my pushState-based URI handling that backbone.js manages for me in an Javascript app.

R

5条回答
  •  盖世英雄少女心
    2020-12-04 12:19

    Here is what i did to my application. Every route ending with a '/' (except the root it self) will serve index.html :

      location ~ ^/.+/$ {
        rewrite .* /index.html last;
      }
    

    You can also prefix your route :

    Backbone.history.start({pushState: true, root: "/prefix/"})
    

    and then :

      location ~ ^/prefix/ {
        rewrite .* /index.html last;
      }
    

    Or define a rule for each case.

提交回复
热议问题