Firebase 如何将404重定向到起始页?

Firebase 如何将404重定向到起始页?,firebase,http-status-code-404,firebase-hosting,Firebase,Http Status Code 404,Firebase Hosting,我刚开始在firebase上托管一个web应用程序。 使用firebase cli(firebase工具)的自动设置在我的公用文件夹中创建了一个404.html文件 但我不想看到自定义404错误页面,也不想看到firebase的默认页面。 我想将所有404重定向到startpage,这样应用程序无论如何都会初始化。(我的webpack dev server本地设置运行正常) 一种解决方法是将相同的内容从index.html放入404.html。但这会导致保养加倍 我在这里找到了一些关于重定向配置

我刚开始在firebase上托管一个web应用程序。 使用
firebase cli
(firebase工具)的自动设置在我的公用文件夹中创建了一个
404.html
文件

但我不想看到自定义404错误页面,也不想看到firebase的默认页面。 我想将所有404重定向到startpage,这样应用程序无论如何都会初始化。(我的
webpack dev server
本地设置运行正常)

一种解决方法是将相同的内容从
index.html
放入
404.html
。但这会导致保养加倍

我在这里找到了一些关于重定向配置的信息。 但是404错误类型的重定向是不可能的。 无法使用
.htaccess
文件


无论是在我的
firebase.json
文件中还是在???

中,我是否缺少更改此行为的正确位置?不确定这是否适用于您,我从未使用
.htaccess
进行过任何操作,但在我的情况下,我始终以这种方式进行修复:

您可以在
firebase.json
文件的“重写”部分中包含一个通配符路由作为最后一个路由,以便任何以前无人认领的路由都将匹配:

"rewrites": [
  {
    // route info here
  },
  {
    // another route
  },
  {
    // If it makes it here, it didn't match any previous routing
    // Match all routes that get to this point and send them to the home page.
    "source": "**",
    "destination": "/index.html"
  }
]

如果您不想留下原始/不存在的url(例如),您可以修改404.html源代码并用js重定向替换它

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Page Not Found</title>
    <script>
      window.location.href = "/";
    </script>
  </head>
</html>

找不到页面
window.location.href=“/”;
是的,是重写!