6

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.

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I had seen it earlier but couldn't exactly figure out how it would work in my case. I gave it a try and came up with the config posted in my question which isn't working. Can you post the pattern for my problem (in question)?
Oh! I got it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.