'Firebase subdomain wildcard to one or more project(s)

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman