Firebase使用1个项目将多个子域托管到应用程序目录

标签 firebase dns subdomain firebase-hosting

我目前有一个具有以下结构的应用程序部署到Firebase托管:

public/
    appSub1/
        index.html
    appSub2
        index.html
    index.html

我已经添加并连接了我的子域,这样
appSub1.mysite.com/ -> app.firebaseapp.com/
appSub2.mysite.com/ -> app.firebaseapp.com/

我正在尝试配置重定向,以将子域与正确的应用子文件夹正确关联,从而
appSub1.mysite.com/ -> app.firebaseapp.com/appSub1/
appSub2.mysite.com/ -> app.firebaseapp.com/appSub2/

如果我手动添加子路径,但不是没有子路径,则该应用仍会正确显示。因此,转到appSub1.mysite.com/只会在空白页上结束,但是转到appSub1.mysite.com/appSub1/最终会在正确的index.html上结束

这是我当前在firebase.json中进行的主机配置
"hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "appSub1.mysite.com/**",
        "destination": "/appSub1/**",
        "type": 301
      },
      {
        "source": "appSub2.mysite.com/**",
        "destination": "/appSub2/**",
        "type": 301
      }
    ]
  },

最佳答案

我建议以下内容:

  • 在Firebase上升级到Blaze计划
  • 使用Firebase多站点托管方法(请参阅:https://firebase.google.com/docs/hosting/multisites)
  • public/app1public/app2分为两个单独的托管项目目标-称为app1app2-因此,默认情况下,托管地址将为app1.firebaseapp.comapp2.firebaseapp.com(或者从2019年5月起,您还将获得一个.web.app域-app1.web.app
  • 通过在域注册表中配置DNS条目来连接各个子域(请参阅:https://medium.com/@fransandi/use-firebase-multisite-hosting-to-associate-multiple-domains-subdomains-to-your-project-ee099109bfe9)
  • 关于Firebase使用1个项目将多个子域托管到应用程序目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53892298/

    相关文章:

    javascript - 按时间倒序对 Firebase 实时数据库中的数据进行排序

    ssl - 虚拟主机重定向不存在的子域

    reactjs - Const 未定义 -> 然而标准解决方案不起作用

    firebase - 有没有办法让 firebase 实时数据库存在系统更快地检测到断开连接

    firebase - SetState为String会返回null,使用Flutter进行Firestore

    dns - Behat + Mink 无法使用代理(DNS 无法解析域名)

    ssl - 从 https 和 https ://www. 重定向到 https://www

    linux - 如何让 DNS 可供公众访问

    .htaccess - 将文件夹重写为子域

    apache - htaccess - 子域作为 GET 参数