Skip to main content

Custom Domain Setup

Connect your own domain to Firebase Hosting for a professional web presence with automatic SSL certificates and global CDN distribution.

Quick Setup Overview

Timeline:

  • Verification: 5-30 minutes
  • DNS propagation: 0-48 hours
  • SSL certificate: 0-24 hours after DNS

Step-by-Step Guide

Step 1: Add Custom Domain

  1. Go to Firebase Console
  2. Select your project → Hosting
  3. Click Add custom domain
  4. Enter your domain (e.g., example.com)

Step 2: Verify Domain Ownership

Firebase provides a TXT record for verification:

Type: TXT
Host: @ (or your domain)
Value: firebase=YOUR_VERIFICATION_CODE
TTL: 3600 (or default)

Verification Methods:

  • TXT record (recommended) - Doesn't affect site
  • Upload HTML file - Alternative method
  • Existing Google verification - If previously verified

Step 3: Configure DNS Records

After verification, add these records:

For apex domain (example.com):

Type: A
Host: @
Value: 151.101.1.195
TTL: 3600

Type: A
Host: @
Value: 151.101.65.195
TTL: 3600

Type: AAAA (IPv6)
Host: @
Value: 2a00:1450:4010:c08::65
TTL: 3600

For subdomain (www.example.com):

Type: CNAME
Host: www
Value: YOUR-PROJECT.web.app
TTL: 3600

Domain Configuration Patterns

Pattern 1: Apex + WWW Redirect

Most common setup - example.com redirects to www.example.com:

{
"hosting": {
"redirects": [{
"source": "https://example.com/**",
"destination": "https://www.example.com/:splat",
"type": 301
}]
}
}

Pattern 2: WWW to Apex Redirect

Prefer non-www - www.example.com redirects to example.com:

{
"hosting": {
"redirects": [{
"source": "https://www.example.com/**",
"destination": "https://example.com/:splat",
"type": 301
}]
}
}

Pattern 3: Multiple Domains

Point multiple domains to same site:

  1. Add each domain in Firebase Console
  2. Configure DNS for each
  3. Set up redirects to primary domain:
{
"hosting": {
"redirects": [
{
"regex": "^https://example\\.(net|org)/(.*)$",
"destination": "https://example.com/:2",
"type": 301
}
]
}
}

SSL Certificate Management

Automatic SSL Provisioning

Firebase automatically:

  • Generates SSL certificates via Let's Encrypt
  • Renews certificates before expiration
  • Supports wildcard certificates for subdomains
  • Provides A+ SSL rating

SSL Provisioning Timeline

Troubleshooting SSL Issues

IssueCauseSolution
SSL pending > 24hDNS not propagatedCheck DNS with dig command
Certificate errorOld DNS cacheClear browser cache, wait
Mixed content warningsHTTP resourcesUpdate all resources to HTTPS
SSL not renewingDNS changedReverify domain

Advanced DNS Configurations

Using Cloudflare

If using Cloudflare DNS:

  1. Set SSL/TLS to "Full" (not Flexible)
  2. Disable proxy (orange cloud) initially
  3. Add records as shown above
  4. Wait for SSL provisioning
  5. Enable proxy after SSL is active (optional)

DNS Provider-Specific Guides

GoDaddy:

1. DNS Management → Add → A Record
2. Host: @, Points to: Firebase IPs
3. Save changes

Namecheap:

1. Advanced DNS → Add New Record
2. Type: A Record, Host: @
3. Value: Firebase IPs

Google Domains:

1. DNS → Custom records
2. Add A records with Firebase IPs
3. Add AAAA records for IPv6

Subdomain Strategies

Subdomain Setup

Different subdomains for different purposes:

# Main site
example.com → Marketing site

# Application
app.example.com → Web application

# API
api.example.com → Cloud Functions/Run

# Documentation
docs.example.com → Documentation site

# Staging
staging.example.com → Test environment

Wildcard Subdomains

For dynamic subdomains (e.g., user.example.com):

  1. Not directly supported by Firebase Hosting
  2. Use Cloud Run with custom domain mapping
  3. Or implement routing logic in Cloud Functions

Domain Migration

Moving from Another Host

  1. Reduce TTL - 24 hours before migration

    Old TTL: 86400 → New TTL: 300
  2. Set up Firebase - Complete verification

  3. Update DNS - Point to Firebase

  4. Monitor traffic - Check analytics

  5. Increase TTL - After successful migration

    TTL: 300 → TTL: 3600

Zero-Downtime Migration

Email Configuration

Important: Email Hosting

Firebase Hosting does NOT provide email services. When moving domains:

  1. Keep existing MX records
  2. Only update A/AAAA records
  3. Don't delete email-related records

Example DNS with email:

# Website (Firebase)
A @ 151.101.1.195
AAAA @ 2a00:1450:4010:c08::65

# Email (Keep existing)
MX @ 10 mail.example.com
TXT @ "v=spf1 include:..."

Monitoring Domain Health

DNS Verification Tools

# Check A records
dig example.com A

# Check AAAA records
dig example.com AAAA

# Check all records
dig example.com ANY

# Check from specific nameserver
dig @8.8.8.8 example.com

# Online tools
# - whatsmydns.net
# - dnschecker.org
# - mxtoolbox.com

SSL Certificate Check

# Check certificate details
openssl s_client -connect example.com:443 -servername example.com

# Check expiration
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates

Troubleshooting Guide

Domain Not Working

Check verification status:

  1. Firebase Console → Hosting → View domains
  2. Look for ⚠️ warning icons
  3. Re-verify if needed

Verify DNS propagation:

# Should return Firebase IPs
nslookup example.com
dig example.com

Common DNS issues:

  • Cached old records → Wait or flush DNS
  • Wrong record type → Use A for apex, CNAME for subdomain
  • Proxy enabled → Disable Cloudflare proxy initially

"Website Not Secure" Error

Causes:

  1. SSL still provisioning (wait up to 24h)
  2. DNS not fully propagated
  3. Mixed content (HTTP resources)
  4. Browser cache (try incognito)

Solutions:

// Force HTTPS redirect
if (location.protocol !== 'https:') {
location.replace('https:' + window.location.href.substring(window.location.protocol.length));
}

Redirect Loops

Common cause: Conflicting redirects

{
"hosting": {
"redirects": [
{
"source": "/",
"destination": "https://www.example.com/",
"type": 301
}
],
"headers": [{
"source": "**",
"headers": [{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains; preload"
}]
}]
}
}

Best Practices

1. Domain Setup Checklist

  • Reduce TTL before migration
  • Verify domain ownership
  • Add all required DNS records
  • Test with Firebase URL first
  • Monitor SSL provisioning
  • Set up redirects (www/non-www)
  • Update sitemap.xml
  • Submit to Search Console

2. Security Headers

{
"headers": [{
"source": "**",
"headers": [
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
}
]
}]
}

3. SEO Considerations

  • Use 301 redirects for permanent moves
  • Update canonical URLs
  • Maintain URL structure if possible
  • Update internal links
  • Monitor search rankings

Advanced Configurations

Internationalization Domains

# Country-specific domains
example.com → International (English)
example.de → Germany
example.fr → France
example.co.uk → United Kingdom

Configure with i18n:

{
"hosting": {
"i18n": {
"root": "/localized-content"
}
}
}

Domain Aliases

For multiple domains pointing to same content:

  1. Add all domains in Firebase Console
  2. Choose primary domain
  3. Redirect others to primary
  4. Update canonical tags

Cost Considerations

What's Free

  • ✅ SSL certificates
  • ✅ Unlimited custom domains
  • ✅ Automatic renewals
  • ✅ Global CDN distribution

Potential Costs

  • Domain registration (external)
  • Premium DNS services (optional)
  • Bandwidth usage (standard Firebase pricing)

Next Steps


Pro Tip: Always verify DNS changes from multiple locations using online tools. DNS propagation can vary by region, and checking from different locations ensures global availability! 🌍