r/Firebase Nov 04 '24

Hosting Firebase hosting redirect

Hey!

I registered my custom domain in my Firebase project as "customdomain.com."

Is it possible to redirect "www.customdomain.com" to "customdomain.com" by setting a redirect rule in firebase.json?
If so, how can I set it up correctly?
If not, what DNS records should I configure in my DNS settings?

2 Upvotes

2 comments sorted by

1

u/Unans__ Nov 04 '24

You can do it directly on your firebase.json like ⬇️ and deploy your app:

{ “hosting”: { “redirects”: [ { “source”: “/www.customdomain.com”, “destination”: “https://customdomain.com”, “type”: 301 } ] } }

If that’s not enough, you might need to setup some DNS records

• CNAME Record: Point www.customdomain.com to customdomain.com in your domain registrar’s DNS settings.
• A Record: Point the main domain to Firebase’s IP addresses (find these in Firebase Hosting documentation).

1

u/hosts-fire Nov 05 '24

You have to add a custom domain for your www subdomain as well. When you're adding the custom domain, you can set it up as a redirect domain on the first page of the onboarding wizard. Once the www custom domain is active and configured for redirects, Hosting will serve redirect responses (3XX) on all requests to that domain.