Firebase Dynamic Links — root url

11,091

Another way to set up a redirect from the root dynamic link domain (without serving a page with a javascript redirect) is by adding a redirect rule like this one to your firebase.json file:

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

This rule will exist alongside your dynamic link rewrite rule(s), so for a simple setup where all paths except the root are treated as dynamic links, your firebase.json might look like this:

{
  "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
    } ]
  }
}

To access and modify your firebase.json file, you'll have to set up firebase hosting with the Firebase CLI if you haven't already: https://firebase.google.com/docs/hosting

This page explains more about the firebase.json file and how to use rewrite and redirect rules: https://firebase.google.com/docs/hosting/full-config

Share:
11,091
Pavel
Author by

Pavel

Flutter, Python

Updated on June 09, 2022

Comments

  • Pavel
    Pavel about 2 years

    I'm using Firebase Dynamic Links to redirect users to mobile app.

    Links like https://example.com/mypath works, but I also want to use root url, i.e. https://example.com

    Currently it shows error:

    Invalid Dynamic Link

    Requested URL (https://example.com/) must be a parsable and complete DynamicLink.

    If you are the developer of this app, ensure that your Dynamic Links domain is correctly configured and that the path component of this URL is valid.

    When I try to set up a link without prefix, it shows error:

    Short URL is required

    Is it any way to set up root url?

  • Nelu
    Nelu about 3 years
    This applies to Android apps only, correct? I'm getting the error on iOS but Firebase settings don't have a place to add SHA to the iOS app, only Android (which is the case in the video you linked also).
  • bastami82
    bastami82 about 3 years
    @Nelu sorry for the delayed reply, have no clue what you need to do with iOS tbh, but I assume there must be official iOS videos too. sorry for not being more help here