Search code examples
firebase.htaccessfirebase-hosting

How to implement this .htaccess in firebase?


I have this .htaccess for a PWA

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

I want to migrate the app to firebase, basically what it does is let's say I shared this link

example.com/pwa/giftLink

He gets redirected to PWA

example.com/pwa

And the PWA redirects him to giftLink. I don't want to do it via code, I prefer doing it via firebase.json


Solution

  • In Firebase Hosting rewrites, the equivalent would be:

    "hosting": {
      // ...
    
      // Add the "rewrites" attribute within "hosting"
      "rewrites": [ {
        "source": "/pwa{,/**}",
        "destination": "/pwa/index.html"
      } ]
    }