Prog blog
Inventory

How to redirect 301 in firebase

How to redirect 301 in firebase

While moving the blog to IPNS, I decided to make it easier for Google Bot to find my new address by adding the redirection of all blog-81003.web.app traffic using HTTP code 301. As the blog was previously on Firebase Hosting, I had to modify the firebase hosting configuration by adding the following redirections.

firebase.json

{
  "hosting": {
    "redirects": [
      {
        "source": "/:path*",
        "destination": "https://k2k4r8ox4iruav3sij20d6ibh32ka07rxwcvgf78phjmbnhkvaovdirf.ipns.dweb.link/:path",
        "type": 301
      },
      {
        "source": "/",
        "destination": "https://k2k4r8ox4iruav3sij20d6ibh32ka07rxwcvgf78phjmbnhkvaovdirf.ipns.dweb.link/",
        "type": 301
      }
    ]
  }
}

The first rule makes each blog subpage return 301 to

https://k2k4r8ox4iruav3sij20d6ibh32ka07rxwcvgf78phjmbnhkvaovdirf.ipns.dweb.link/(path-to-subpage)

The second rule moves all queries from the main page to the new address.

After modifying the configuration, all you have to do is send the modifications to the firebase servers with this command.

npm run firebase deploy -- --only hosting

After a while, each page will display redirection 301 on the old address.