Search code examples
firebasefirebase-hosting

Firebase Hosting rewrite glob behaviour issue


I have set up a firebase hosting project with three pages and my custom domain setup . These pages get hit based on different paths in the url. The firebase.json file is as follows

{

    "hosting": {

    "public": "public",

   "ignore": [
     "firebase.json",
     "**/.*",
     "**/node_modules/**"
    ],

   "rewrites": [ {
       "source": "/main",
       "destination": "/index.html"
   },{
       "source": "/waitlistview/**",
       "destination": "/waitlistview.html"
   },{
       "source": "/mwaitlistview/**",
       "destination": "/waitlistview-minimal.html"  
   } 
   ],

   "cleanUrls": true
   }
}

Now when i try a url :

foodini.co.in/waitlistview

Instead of getting an error with 404 page, i still hit my page

Whereas if i hit the url:

foodini.co.in/mwaitlistview

I get the 404 page as i expect.

How to i make the first url to also go to 404 page


Solution

  • According to firebase hosting docs, Hosting first tries to map a file inside the public directory to the path in the url. Only if there is no such file will a rewrite take effect.

    In my case, I had a file /waitlistview.html directly inside the public folder. Thus firebase hosting just mapped the url to that file even without a trailing slash. The rewrite never occurred and thus there was no 404 page

    Also for anyone interested:

    your default domain name directly maps to index.html without the need for any specific path

    Also /waitlistview** does not match /waitlistview/Ahmedabad/xyz path via GLOB matching so please have a slash before **