If you’re using Firebase Hosting for your website, you may want to add “www” to your custom domain name to make it easier for visitors to access your site. Fortunately, this is a simple process that can be done in just a few steps.

Step 1: Set up custom domain

Before you can add “www” to your custom domain name, you need to set up your custom domain in Firebase Hosting. To do this, go to the Firebase console and select your project. Then, go to Hosting and click on “Add custom domain.” Follow the prompts to verify your domain and set up your DNS records.

Step 2: Add “www” subdomain

Once your custom domain is set up in Firebase Hosting, you can add the “www” subdomain. To do this, go to your domain registrar and add a CNAME record for “www” that points to your Firebase Hosting subdomain. For example, if your Firebase Hosting subdomain is “my-project.firebaseapp.com”, you would add a CNAME record for “www” that points to “my-project.firebaseapp.com”.

Step 3: Update Firebase Hosting

After adding the CNAME record, you need to update Firebase Hosting to recognize the “www” subdomain. To do this, go back to the Firebase console and select your project. Then, go to Hosting and click on “Add custom domain” again. This time, enter your full custom domain name, including the “www” subdomain. Follow the prompts to verify your domain and update your DNS records.

Step 4: Wait for DNS propagation

After making these changes, it may take some time for DNS propagation to occur. This means that it may take a few hours or even up to 48 hours for the changes to take effect. Once DNS propagation is complete, visitors to your site will be able to access it using either your custom domain name or the “www” subdomain.

How to add a redirect in firebase

It’s easy to redirect www to non-www/root domain in Firebase Hosting Console. When adding a www custom domain, simply select the redirect option and tick the box. Then, enter the destination address, which should be your non-www domain name. For reference, you can take a look at the screenshot below.

Redirect subdirectory links

in above option we saw that how to redirect a subdomain, we can also do this by adding redirect blocks in firebase.json. see the sample of a “/question” as “/faq

"hosting": {
"redirects": [ {
"source": "/question",
"destination": "/faq",
"type": 301
} ]
}

In conclusion, adding “www” to your custom domain name in Firebase Hosting is a simple process that can be done in just a few steps. By following these steps, you can make it easier for visitors to access your site and improve your site’s overall user experience.

Related Posts