How do I make a custom subdomain on Firebase?

25,405

Solution 1

Update

You can now add multiple domains to a single Firebase Hosting site. Domains can either serve site content or redirect to another domain (editable at any time). In addition, you can now use subdomains of the same registered domain on different projects, such as example.com on one project and blog.example.com on another. Visit your hosting admin page to configure them.

Original answer

If you point multiple subdomains of mydomain.com to Firebase Hosting, it will redirect others to the one you chose when specifying your custom domain. If you're looking to simply serve content from one subdomain, all you need do is specify that one in the custom domain field on you Hosting tab and point your DNS for that subdomain to Firebase Hosting, following the instructions provided.

If, however, you're looking to serve different content on different subdomains, that's not currently possible, though this is a highly requested feature that we're considering implementing

Solution 2

i believe you can use rewritte rules on the hosting configuration json file

since all domains and subdomains you point to your firebase project will be redirected to your single firebase hosting bucket, youll need to set up custom rewrite rules for each domain you want to separate, to redirect them to an specific folder or cloud function in your project.

i suggest to check the next url as reading material, its a new techinque to work with projects in firebase https://github.com/jthegedus/firebase-functions-next-example

on your firebase.json file

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/.well-known/assetlinks.json",
        "destination": "/instant/assetlinks.json"
      },
      {
        "source": "sub.domain.com/**",
        "destination": "/subdomain/**"
      }
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  }
}
Share:
25,405

Related videos on Youtube

Doug Liu
Author by

Doug Liu

Updated on October 24, 2020

Comments

  • Doug Liu
    Doug Liu over 3 years

    I have purchased a domain ("www.mydomain.com"). How do I make a subdomain on Firebase ("sub.mydomain.com"), if I am using Firebase hosting?

    • James Moore
      James Moore about 4 years
      FYI, you purchased mydomain.com. Anything below that is up to you - dougliu.mydomain.com, www.mydomain.com, what.ever.mydomain.com are all things you control.
  • David
    David almost 9 years
    Hey @Chris, Please do the different content on different subdomains feature asap :D any updates there?
  • Chris Raynor
    Chris Raynor over 8 years
    Firebase Hosting fully supports apex domains - you can specify an apex domain instead of a subdomain when setting the custom domain, and Firebase Hosting will redirect all subdomains to the apex. We'll provide the A-Record entries you'll need to set up an apex domain, and you can choose between A-Records or a CNAME for the subdomains
  • Qiming
    Qiming about 8 years
    @Chris with the new firebase update is it possible to point different apps to different subdomains?
  • Chris Raynor
    Chris Raynor about 8 years
    No, it's still not possible. It's something we understand users really want and we would love to offer, but I'm afraid can't share any time frames for when it might be ready
  • Adam Reis
    Adam Reis almost 8 years
    @Chris This is a must have feature, as our application relies on custom subdomains to determine the user sub set/account. We're now forced to look for other hosting elsewhere unfortunately, which is a pity because I love the simplicity of Firebase.
  • pinglock
    pinglock over 3 years
    @kato Are there published instructions on how to make this work? Jose's answer above doesn't seem to work.