Prottay
Prottay

Reputation: 460

Firebase redirect user to a new URL when they enter my website

I had previously hosted my website on firebase on this URL: https://oldurl.firebaseapp.com/ and that application is outdated.

Recently I have updated the application and decided to try out Vercel and created an instance of my website on this URL: https://newurl.now.sh/

Now I don't want the user to go to that previous firebase domain and view that outdated application. What I want is to redirect the user from the firebase domain to the new Vercel domain.

Suppose when the user goes to this URL https://oldurl.firebaseapp.com/, I want to redirect them to this URL: https://newurl.now.sh/

How do I do that?

Upvotes: 2

Views: 7220

Answers (1)

Prottay
Prottay

Reputation: 460

If you want to redirect the user to a new URL when they enter your website, edit your project's firebase.json file, like this:

{
  "hosting": {
    "public": "build", //whatever your public directory is
    "redirects": [
      {
        "source": "/",
        "destination": "https://mynewurl.now.sh/",
        "type": 301
      }
    ]
  }
}

Then deploy

I found this solution from a google firebase group

Further information about hosting configuration can be found at https://firebase.google.com/docs/hosting. Rewrites (like the code snippet) are covered in the Configure redirects section.

Upvotes: 12

Related Questions