Firebase 托管 – 无法将默认流量重写为 index.html 以外的任何其他内容

Firebase Hosting – Cannot rewrite default traffic to anything else but index.html

我有几个指向同一目录的 firebase 托管站点。

对于这个特定实例,我希望特定站点使用与 public 文件夹的 index.html 文件不同的默认索引。

我已将子站点 firebase 托管部署设置为与此类似的内容:

{
    "target": "subsite",
    "public": "hosting/public_mysite",
    "headers": [
      {
        "source": "/",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "no-cache, no-store, must-revalidate"
          }
        ]
      }
    ],
    "ignore": [
      "firebase.json",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/about",
        "destination": "/subsite/about.html"
      },
      {
        "source": "/reviews",
        "destination": "/subsite/reviews.html"
      },
      {
        "source": "**",
        "destination": "/subsite/home.html"
      }
    ]
  }

在子站点上,url /about 和 /reviews 确实加载了重写部分中列出的请求的替代页面。

最后一条规则 "source": "**" 似乎被完全忽略了,无论如何 firebase 都会加载 /index.html。

为什么它不加载 /subsite/home.html

该文件肯定与其他文件一起存在。

参见 Priority order of Hosting responses

  1. /__/* 路径段开头的保留名称空间
  2. 配置的重定向
  3. Exact-match静态内容
  4. 配置重写
  5. 自定义 404 页面
  6. 默认 404 页面

访问 / 将在匹配任何 rewrites 之前优先考虑根 index.html。如果您想呈现不同的资源,则必须在没有根的情况下进行部署 index.html.