Search code examples
firebasefirebase-hosting

Firebase Hosting – Cannot rewrite default traffic to anything else but index.html


I have a couple of firebase hosted sites pointing to the same directory.

For this particular instance I would like a specific site to use a different default index than the public folder's index.html file.

I've set the sub-site firebase hosting deployment to something similar to this:

{
    "target": "subsite",
    "public": "hosting/public_mysite",
    "headers": [
      {
        "source": "/",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "no-cache, no-store, must-revalidate"
          }
        ]
      }
    ],
    "ignore": [
      "firebase.json",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/about",
        "destination": "/subsite/about.html"
      },
      {
        "source": "/reviews",
        "destination": "/subsite/reviews.html"
      },
      {
        "source": "**",
        "destination": "/subsite/home.html"
      }
    ]
  }

On the sub-site, the urls /about and /reviews do indeed load the requested alternative pages listed in rewrites section.

The last rule "source": "**" seems to be completely ignored and firebase loads the /index.html anyway.

Why is it not loading /subsite/home.html instead?

The file is definitely there with the other ones.


Solution

  • See Priority order of Hosting responses.

    1. Reserved namespaces that begin with a /__/* path segment
    2. Configured redirects
    3. Exact-match static content
    4. Configured rewrites
    5. Custom 404 page
    6. Default 404 page

    Visiting / will prioritize the root index.html before matching against any rewrites. If you want to render a different resource you'll have to deploy without the root index.html.