Firebase: Pass url Param in URL Rewrite

I know this is an old question but I had a similar issue and didn't find an answer so thought I'd share how I solved it.

{    
    "hosting": {
    // Add the "rewrites" section within "hosting"
        "rewrites": [ {
            "source": "/item/**",
            "destination": "/item.html"
        } ]
}

I solved my issue by rewriting the dynamic URL to the static html page. Since it's a rewrite the URL will stay as the source URL pattern and not change to the destination URL like a redirect would.

We can then read the source URL through window.location.pathname with Javascript on the item.html page. You can then use .split('/') to return an Array to choose the part that you need.

Hope this helps to anybody looking for a similar solution.


I have just received an email from Firebase support with the follwing:

Update From Firebase support:

Your use case is not possible with Firebase Hosting alone. You will need to make use of Cloud Functions as well to do so. Firebase has just recently released a native Firebase Hosting + Functions integration which makes it possible to perform server-side processing so you can redirect URLs to a function where you can write code to dissect the path and generate whatever response you want. You may check our documentations out to know more about it in detail.

https://firebase.google.com/docs/hosting/functions

I have emailed them back to see if this is something that will be added in the future as it seems a little overkill to run to processes for one page.

Update 28/07/2017

Since this is not supported, I have filed a feature request for you. However, I am not able to share any details or timelines for now. We'll keep your feedback in consideration moving forward though.

In the meantime, you may keep an eye out on our release notes.

Have a great day.

https://firebase.google.com/support/releases