首页 > 解决方案 > Firebase 动态链接 — 根 URL

问题描述

我正在使用Firebase 动态链接将用户重定向到移动应用。

链接喜欢的https://example.com/mypath作品,但我也想使用根网址,即https://example.com

目前它显示错误:

无效的动态链接

请求的 URL ( https://example.com/ ) 必须是可解析且完整的 DynamicLink。

如果您是此应用的开发者,请确保您的动态链接域配置正确并且此 URL 的路径组件有效。

当我尝试设置没有前缀的链接时,它显示错误:

短网址为必填项

有没有办法设置root url?

标签: firebasefirebase-dynamic-links

解决方案


从根动态链接域设置重定向的另一种方法(不提供带有 javascript 重定向的页面)是在 firebase.json 文件中添加类似这样的重定向规则:

"redirects": [ {
      "source": "/",
      "destination": "https://example.com/page-for-root-to-redirect-to",
      "type": 301
    } ]

此规则将与您的动态链接重写规则一起存在,因此对于除根以外的所有路径都被视为动态链接的简单设置,您的 firebase.json 可能如下所示:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [ {
      "source": "/**",
      "dynamicLinks": true
    } ],
    "redirects": [ {
      "source": "/",
      "destination": "https://example.com/page-for-root-to-redirect-to",
      "type": 301
    } ]
  }
}

要访问和修改您的 firebase.json 文件,您必须使用 Firebase CLI 设置 Firebase 托管(如果您还没有):https ://firebase.google.com/docs/hosting

本页解释了有关 firebase.json 文件以及如何使用重写和重定向规则的更多信息:https ://firebase.google.com/docs/hosting/full-config


推荐阅读