Enrique Chavez
Enrique Chavez

Reputation: 1429

Firebase Hosting - Wildcard Redirections

I want to use Firebase Hosting to host an angular application and I need to create a redirection to some old files in another URL.

According with the Firebase Documentation you can do basic redirections

"redirects": [ {
    "source" : "/foo",
    "destination" : "/bar",
    "type" : 301
}, {
    "source" : "/firebase/*",
    "destination" : "https://www.firebase.com",
    "type" : 302
} ]

But I need a wildcard redirection

"redirects": [ {
    "source" : "/config/*",
    "destination" : "//oldsiteurl/config/[match-request]",
    "type" : 302
}]

So, basically I need that myapp.firebase.com/config/some.json redirects to //oldsiteurl/config/some.json. I have a lot of json files so I do not want to match file by file.

Did you know if this is possible?

Thanks!

Upvotes: 14

Views: 8696

Answers (3)

gkalpak
gkalpak

Reputation: 48211

For people landing on this page, it is now possible to have wildcards in the URLs:

Sometimes it is desirable to capture parts of the source URL of a redirect and re-use them in the destination. You can do this using a : prefix to identify the segment and an optional * after the name to indicate that it should capture the rest of the URL

(source)

Upvotes: 14

BatManMightBeReal
BatManMightBeReal

Reputation: 61

"redirects": [
      {
        "source": "/subdomain/:random*",
        "destination": "https://subdomain.myapp.com/:random*",
        "type": 301
      }
    ]

Upvotes: 5

Frank van Puffelen
Frank van Puffelen

Reputation: 600071

From the Firebase documentation on URL redirects (emphasis mine):

If a match is found, an HTTP redirect response is set with the "Location" header set to the static destination string, which can be a relative path or an absolute URL.

So it looks like the wild-carded part of the match is not carried over into the redirect.

Upvotes: 2

Related Questions