saibbyweb
saibbyweb

Reputation: 3244

firebase hosting url rewrite pattern matching

How do I rewrite urls like:

http://somedomain.com/page.html

to

http://somedomain.com/DIRECTORY/page.html

in firebase hosting. I tried this in firebase.json but didn't work.

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

How does pattern matching work in firebase hosting config. Help would be appreciated.

Upvotes: 6

Views: 4192

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598668

From the Firebase Hosting documentation on rewrites:

The rewrites attribute contains an array of rewrite rules, where each rule must include:

  • A source specifying a glob pattern

  • A destination, which is a local file that must exist

So it looks like you can only rewrite to a specific, existing file, not to another wildcard.

You could consider using redirects instead, since those do support dynamic segments in their destination URL.

"redirects": [ {
  "source": "/:page*",
  "destination": "http://somedomain.com/DIRECTORY/:page",
  "type": 301
}]

This sends a redirect instruction back to the client, so they will be able to see what the final path is.

Upvotes: 7

Related Questions