pinglock
pinglock

Reputation: 1253

Firebase Hosting rewrites not working properly

I currently have the following configuration:

// firebase.json   
{
        "hosting": [
            {
                "rewrites": [{
                    "source": "/articles{,/**}",
                    "destination": "/articles"
                },
                {
                    "source": "**",
                    "destination": "/index.html"
                }]
            }
        ]
 }

If I go to mysite.com/articles/<articleID> I'm taken to mysite.com when I'd expect to be taken to mysite.com/articles. What am I doing incorrectly?

I'm following this documentation.

Upvotes: 2

Views: 2420

Answers (2)

pinglock
pinglock

Reputation: 1253

I was able to resolve the issue after taking the following steps:

  1. Change my source from /articles{,/**} to /articles/**
  2. Change my destination from articles to articles.html which is a valid local file
  3. Realize that changes to firebase.json don't change the behavior of the Firebase Hosting emulator until it is restarted.

Upvotes: 1

shivaramanaiyer
shivaramanaiyer

Reputation: 615

I believe there are two possible causes.

  1. You have set hosting as an array instead of an object (although I am not completely sure if that is an issue)
  2. Secondly, as you can see in the documentation you shared, just above the heading Direct requests to a function, it says that the destination file must exist and as mysite.com/articles doesn't evaluate to a local file, it is caught by the second rewrite rule and redirected to index.html.

Upvotes: 0

Related Questions