有条件地使 Nginx 重定向到 index.html

Conditionally make Nginx redirects to index.html

如何为所有 url 重定向到 index.html,除非 url 有一个特定的 QueryString?

例如:

将所有其他带有查询字符串的 url 重定向到 index.html,除非它具有 ngsw-cache-bust

 example.com/ngsw.json?ngsw-cache-bust=0.24039143891136616

我试过下面的代码

    server {
      index index.html;
      root /dist;
      listen 80;
      location / {
        try_files $uri$args $uri$args/ /index.html;
      }
  }

我错过了什么?

也许你可以尝试这样的事情

 server {
      index index.html;
      root /dist;
      listen 80;
      location / {
        if($arg_ngsw-cache-bust == "") {
          rewrite ^(.*)$ /index.html last;
        }
      }
  }