重写firebase.json的规则以配置Firebase托管

时间:2020-05-04 20:34:01

标签: javascript firebase .htaccess url-rewriting firebase-hosting

我正在开发一个Web应用程序,并将所有文件托管在Firebase Hosting上。

到目前为止,我的页面网址看起来像

mydomain.com/user/index.html?user=username

但是当我输入

mydomain.com/username

其行为应相同。应该有什么规则?

我尝试了这个但没用

{
  "hosting": {
    "public": "psNew4",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "redirects": [ {
    "source": "/user/index.html?user=:username", // username is dynamic
    "destination": "https://example.com/:username",
    "type": 301
  }]
  }
}

PS:username是动态的

有没有解决办法?

1 个答案:

答案 0 :(得分:0)

根据capturing URL segments for redirects上的Firebase文档,您正在寻找以下内容:

"hosting": {
  // ...

  "redirects": [ {
    "source": "/user/index.html?user=:username",
    "destination": "https://example.com/:username",
    "type": 301
  }]
}