Firebase subdomain wildcard to one or more project(s)

1.2k views Asked by At

We are writing a project for schools. We need different subdomains to any school and users should be different. Any email can be registered on different subdomains as other user.

So we want to connect our domain and all subdomains to a project with *.example.com wildcard. We will read subdomains as values. I think we can manage it with the structure below.

Example 1;

     requestUrl           |       firebaseProject                 |       displayUrl
https://example.com      ==> https://projectMain.firebaseapp.com ==> https://example.com
https://sub1.example.com ==> https://projectSub1.firebaseapp.com ==> https://sub1.example.com
https://sub2.example.com ==> https://projectSub2.firebaseapp.com ==> https://sub2.example.com

/// OR

Example 2;

     requestUrl           |       firebaseProject             |       displayUrl
https://example.com      ==> https://project.firebaseapp.com ==> https://example.com
https://sub1.example.com ==> https://project.firebaseapp.com ==> https://sub1.example.com
https://sub2.example.com ==> https://project.firebaseapp.com ==> https://sub2.example.com

Is that posible or not?

2

There are 2 answers

1
Michael Bleigh On BEST ANSWER

Unfortunately, this is not supported by Firebase Hosting. There can only be a single canonical domain for a Hosting site, and any other subdomain will be redirected to the canonical domain.

0
Tersyas On

An update to the original best answer, Firebase hosting is now available on handling wildcards.

For Example 1: This can be achieved by multi-hosting provided by Firebase Hosting. Go to the Hosting section of Firebase Console, then click add another page.

requestUrl      |   firebase sites of same project  |   displayUrl
www.domain.com  =>         www.firebase.app        =>  www.domain.com
xyz.domain.com  =>         xyz.firebase.app        =>  xyz.domain.com

For Example 2: Simply go to Firebase Console and redirect the subdomain to your desired domain and make sure to modify your A records on your DNS provider.

requestUrlToRedirect     |    firebaseProject
www.domain.com           =>      domain.com