firebase - Firebase 中具有 glob 模式的动态重写规则

标签 firebase firebase-hosting

我有一个“项目详细信息”页面的 URL 结构,如下所示:john/project/eRdKn6(其中“john”是用户名,“eRdKn6”是项目 ID)。我希望将其重写到文件 project.html 中,我在其中解析 document.location 并加载适当的数据。因此用户名和项目 ID 应该是动态的。

我的 firebase.json 中的规则如下所示:

{
  "source": "*/project/*",
  "destination": "/project.html"
}

但是,当我尝试加载 http://example.com/john/project/eRdKn6 时,Firebase 404 出现了。

我尝试仅将最后一部分设为动态,作为测试(例如 {"source": "john/project/*", "destination": "/project.html"} 但我也得到了 404。

project.html 位于 public 文件夹中。

这是我的完整 firebase.json 文件:

{
  "firebase": "example",
  "public": "public",
  "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
  ],
  "rewrites": [
    {"source": "*/project/*", "destination": "/project.html"}
  ]
}

最佳答案

问题似乎是 source 需要一个起始斜杠,例如/*/项目/*。我的完整 firebase.json 现在如下所示:

{
  "firebase": "example",
  "public": "public",
  "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
  ],
  "rewrites": [
    {"source": "/*/project/*", "destination": "/project.html"}
  ]
}

这似乎是一个文档问题,因为没有一个示例涵盖此用例。

关于firebase - Firebase 中具有 glob 模式的动态重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35199160/

相关文章:

firebase - 没有自定义 URL/后缀的动态链接

twitter-bootstrap - 在 Bootstrap 模式中捕获 Firebase 错误

firebase - 字段 SCREEN_VIEW 不是有效维度

node.js - Firebase 托管设置问题

npm - firebase 部署错误 : 'eslint is not recognized as an internal or external command, operable program or batch file'

reactjs - firebase 托管上的 Nextjs 在页面刷新时返回 404

Node.js 应用程序无法在 Cloud Functions for Firebase 中渲染 hbs

ios - 使用 Firebase 发送消息

javascript - Next Js - Firebase 部署问题

javascript - 如何在 Firebase 实时数据库 (v9) 中增加值