Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exclude a path (/images) from single page app rewrite?

I have a react app and have the usual rewrite rule in firebase hosting:

   "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

I also have a separate /images directory with images I don't want to be rewritten.

How do I exclude the /images directory from the rewrite?

like image 277
Duane Avatar asked Mar 07 '23 05:03

Duane


2 Answers

I'm a bit late but I found this question while searching for a similar problem.

Use this rewrites rule :

"rewrites": [
  {
    "source": "!/images/**",
    "destination": "/index.html"
  }
]

The key is that "source" (as a lot of fields in firebase.json) use a glob pattern matching notation. Instead of redirecting everything on index.html (as do " ** "), this rule redirect everything that is not in the images folder and subfolders.

like image 58
Gerard Walace Avatar answered Mar 16 '23 01:03

Gerard Walace


"hosting": {
  "rewrites": [
    {
      "source": "/images/**",
      "destination": "/something.html"
    },
    {
      "source": "**",
      "destination": "/index.html"
    }
  ]
}

This will exclude everything inside your /images folder rewriting it to /something.html

like image 31
Pado Avatar answered Mar 16 '23 01:03

Pado