【问题标题】:Firebase rewrite issues for script and html files脚本和 html 文件的 Firebase 重写问题
【发布时间】:2018-02-15 05:03:07
【问题描述】:

我正在使用 firebase 创建一个电子商务网站。我有多个网页,这些网页应该可以从根节点访问。
例如:www.example.com/
www.example.com/retailer
www.example.com/dashboard
我不希望网站像 www.example.com/retailer/dashboard

而我的重写规则是这样的

"hosting": {
"public": "public",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [
  {
    "source": "/retailer",
    "destination": "/retailer.html"
  },
  {
    "source": "/[dD][aA][sS][hH][bB][oO][aA][rR][dD]",
    "destination": "/dashboard.html"
  },

  {
    "source": "/",
    "destination": "/index.html"
  },


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

]

}

现在我在编写firebase的重写规则时遇到了2个问题

对于 index.html 和 retailer.html 文件,我的应用程序分别在 www.example.comwww.example.com/retailer 上运行,但是当我尝试通过 www.example.com/dashboard 访问我的 dashboard.html 我得到 error.html 页面,但我可以通过 www 访问 dashboard.html 页面.example.com/retailer/dashboard .我不想要这种行为

我的第二个问题是,当我尝试从 www.example.com/retailer/dashboard 获取 dashboard.html 页面时,我的 javascript 和 css 是没有收到在客户端而不是那些脚本我得到了我的脚本的 error.html 页面内容,我得到了云功能的相同行为。

现在我的项目结构是这样的

root ->
  firebase.json
  functions
  public->
        dashboard.html
        error.html
        index.html
        retailer.html
        java-scripts->
                index.js
                retailer.js
                dashboard.js
        css-scripts
        common-scripts
        config-scripts

}

【问题讨论】:

    标签: firebase url-rewriting url-routing google-cloud-functions firebase-hosting


    【解决方案1】:

    首先,我建议您删除对error404.html 的重写,并将文件重命名为404.html。这将或多或少以相同的方式运行,但实际上会返回 404 响应代码。

    您不需要将/ 重写为/index.html,这会自动发生。

    看起来您正在尝试接受任何仪表板案例 - 这真的有必要吗?我可能会建议像您为零售商所做的那样对仪表板进行重写,并对全大写版本进行重定向:

    {
      "hosting": {
        "redirects": [
          {"source": "/DASHBOARD", "destination": "/dashboard", "type": 301}
        ],
        "rewrites": [
          {"source": "/retailer", "destination": "/retailer.html"},
          {"source": "/dashboard", "destination": "/dashboard.html"}
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2013-06-10
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多