如何通过 firebase 托管将我的主页重定向到随机 url?

2024-05-27

我正在尝试使用 firebase 托管通过 302 重定向来重定向我的主页。

"redirects" :[{
    "source": "/",
    "destination": "what do i put here?",
    "type": 302

    }
]

在我的公共文件夹中,有index.html、404.html 和一个装满文件的文件夹。 我希望我的主页随机重定向到这些文件之一。

我知道您可以使用 location.href/assign/replace 在 index.html 中进行重定向,但我必须通过 302 重定向来完成此操作。

Thanks.


一种可能的替代解决方案,涉及云功能:

在 firebase.json 中

"hosting": {
  "rewrites": [
    {
      "source": "**",
      "function": "randomRedirect"
    }
  ]
}

在函数的 index.ts 中(假设是 TypeScript):

export const randomRedirect = functions.https.onRequest((_, res: functions.Response) => {
    res.redirect(302, 'your desired URL');
});

编辑:你need删除 index.html 文件以更改地址栏中的 URL。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过 firebase 托管将我的主页重定向到随机 url? 的相关文章

随机推荐