【问题标题】:Firebase Hosting - Wildcard RedirectionsFirebase 托管 - 通配符重定向
【发布时间】:2015-12-07 07:37:39
【问题描述】:

我想使用 Firebase 托管来托管一个 Angular 应用程序,我需要创建一个重定向到另一个 URL 中的一些旧文件。

根据 Firebase 文档,您可以进行基本重定向

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

但我需要通配符重定向

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

所以,基本上我需要 myapp.firebase.com/config/some.json 重定向到 //oldsiteurl/config/some.json。我有很多 json 文件,所以我不想逐个文件匹配。

你知道这是否可能吗?

谢谢!

【问题讨论】:

    标签: firebase firebase-hosting


    【解决方案1】:

    对于登陆此页面的用户,现在可以在 URL 中使用通配符:

    有时需要捕获重定向的源 URL 的一部分并在目标中重新使用它们。您可以使用 : 前缀来标识段,并在名称后使用可选的 * 来指示它应该捕获 URL 的其余部分

    (source)

    【讨论】:

      【解决方案2】:

      来自Firebase documentation on URL redirects(强调我的):

      如果找到匹配项,则会设置 HTTP 重定向响应,并将“Location”标头设置为 static 目标字符串,该目标字符串可以是相对路径或绝对 URL。

      所以看起来匹配的通配符部分没有被转移到重定向中。

      【讨论】:

        【解决方案3】:
        "redirects": [
              {
                "source": "/subdomain/:random*",
                "destination": "https://subdomain.myapp.com/:random*",
                "type": 301
              }
            ]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-10-02
          • 2016-03-16
          • 2021-09-12
          • 2019-09-10
          • 1970-01-01
          • 2020-10-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多