Search code examples
firebasehttp-status-code-404firebase-hosting

How to redirect 404 to start page?


I just started to host a web application on firebase. the automatic setup with the firebase cli (firebase-tools) created a 404.html file in my public folder.

but i don't want to see a custom 404 error page nor the default one from firebase. I would like to redirect all 404 to the startpage, so that the app will get initialised anyway. (my local setup with webpack-dev-server is just working fine)

a workaround is just to put the same content from index.html into the 404.html. But this leads into doubled maintenance..

i found some information about redirect configuration here https://firebase.google.com/docs/hosting/url-redirects-rewrites. but a redirect for 404 error types isn't possible. using a .htaccess file isn't possible.

am i missing the right location to change this behaviour whether in my firebase.json file or in the https://console.firebase.google.com/??


Solution

  • Not sure if this will work for you, I've never done stuff with .htaccess, but in my case I've always fixed it this way:

    You can include a wildcard route as the last route in the rewrites section of your firebase.json file, so any previously unclaimed routes will match:

    "rewrites": [
      {
        // route info here
      },
      {
        // another route
      },
      {
        // If it makes it here, it didn't match any previous routing
        // Match all routes that get to this point and send them to the home page.
        "source": "**",
        "destination": "/index.html"
      }
    ]