9
votes

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?

4
What's the purpose of using root domain. Suppose if u hit the url www.example.com in your mobile browser It should open your website instead of your mobile app. I think that would be the right behaviour. - Sandeep
@Sandeep while example.com opens website, I want to make app.example.com opens mobile app. That's why I need root domain - Pavel
the app.example.com also represent a url to a blog where example.com is the domain. So you can't use it as a dynamic link in firebase. Expected url is app.example.com/app - Sandeep
@Sandeep what do you mean by "blog"? My site doesn't have a blog. The url app.example.com is already handled by firebase dynamic links. But firebase shows error I posted in the question - Pavel
You need to understand the components of URL. any thing such as www.example.com or www.app.example.com is know as hostname and subdomain. Therefore to create a dynamic link with a deep link you need to provide a PATH name followed by *example.com/APP. In the pic you have used slash /, which will not work you need to provide a string (PATH) over there. Without that dynamic link cannot be created - Sandeep

4 Answers

0
votes

I had this same problem. What I wanted to do is forward the root domain to a different URL. What I did was set up firebase hosting on that domain. Then on the index.html file, I wrote a javascript redirect.

<script>
window.location = "https://www.example.com";
</script>

If you need any more help, please feel free to reply to this and I will help you.

0
votes

If you also happen to use Cloudflare, my solution to this problem was to add a subdomain to Firebase dynamic links and make the main url redirect to the subdomain using page rules.

This way, you can setup it up to work like this:

  • example.com/url -redirect_to-> subdomain.example.com/url (and load dynamic link)
  • example.com/ -redirect_to-> main site or whatever you want
0
votes

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

0
votes

As an Android user, I had sort of same issue, I did manage to get this sorted finally, just in case someone else has the same issue as mine I put what I did:

so if you getting the same issue, which is by typing following in your browser and you do not see any data, then this means your Firebase project is not fully registered with the sha256 key.

 https://YOURLINK.page.link/.well-known/assetlinks.json 

In my case, I had to add a new sha256 key to my firebase project, apparently for dynamic links to work Firebase project MUST be signed with the sha256.

This official firebase video should keep you going: https://youtu.be/zra2DCd0DnY