我正在尝试使用 Firebase 托管通过 302 重定向来重定向我的主页。
"redirects" :[{
"source": "/",
"destination": "what do i put here?",
"type": 302
}
]
在我的公用文件夹中,有index.html、404.html 和一个装满文件的文件夹。 我希望我的主页随机重定向到这些文件之一。
我知道你可以使用location.href/assign/replace在index.html中进行重定向,但我必须通过302重定向来实现。
谢谢。
最佳答案
可能的替代解决方案,涉及云功能:
在 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');
});
编辑:您需要删除index.html 文件才能更改地址栏中的URL。
关于json - 如何通过 firebase 托管将我的主页重定向到随机 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58479587/