🌐 DevOps

Migrating to Firebase Hosting: Multi-Site, CI/CD, and Custom Domains

A practical walkthrough of migrating a React + Vite site to Firebase Hosting with multi-site targets, GitHub Actions CI/CD, and canonical domain redirects.

May 2026

Code deployment pipeline with continuous integration

Firebase Hosting offers global CDN delivery, atomic deployments, and a generous free tier — making it an excellent choice for marketing sites, web apps, and pre-rendered SSR projects. Here is how to set it up properly with multi-site targets, automated deploys, and canonical redirect rules.

Multi-site targets for canonical redirects

Firebase Hosting supports multiple sites per project. Use two targets: one serving your canonical domain (e.g. dexico.in) and a second that issues 301 redirects from the legacy Firebase subdomain (dexico-62a63.web.app) and www to the canonical URL.

Configure targets in .firebaserc and define each site's hosting rules in firebase.json with a redirects block pointing all traffic to your canonical domain. This ensures search engines consolidate link equity and users always land on the right URL.

GitHub Actions CI/CD with secrets

Automate deploys with the FirebaseExtended/action-hosting-deploy GitHub Action. Store your Firebase service account JSON as a repository secret and pass environment variables like API endpoints as VITE_ prefixed secrets at build time.

Never commit .env files. Use .gitignore to block them locally and git rm --cached to remove any that were accidentally tracked. The build step in your workflow should run the full pre-render pipeline (npm run build:all) before deploying, so pre-rendered HTML reaches the CDN.

Custom domain DNS setup

In the Firebase Console, verify ownership of your apex domain and add the TXT record provided. Then point your A records to Firebase's two IP addresses and add a CNAME for www pointing to your Firebase subdomain.

Firebase provisions a free managed TLS certificate automatically once DNS propagates (usually within 24 hours). Remove any conflicting CNAME records on the apex — most DNS providers treat apex A records and CNAMEs as mutually exclusive.

Key takeaways

  • Two hosting targets enforce canonical domain and eliminate duplicate content
  • VITE_ secrets injected at build time — never committed to the repo
  • Free managed TLS certificate provisioned automatically by Firebase
← Back to all posts