问题
I am trying to redirect my homepage with 302 redirect using firebase hosting.
"redirects" :[{
"source": "/",
"destination": "what do i put here?",
"type": 302
}
]
In my public folder, I have the index.html, 404.html, and a folder full of files. I would like for my homepage to randomly redirect to one of those files.
I know you can redirect in the index.html with location.href/assign/replace, but I have to do it through 302 redirect.
Thanks.
回答1:
A possible alternative solution, involving Cloud Functions:
In firebase.json
"hosting": {
"rewrites": [
{
"source": "**",
"function": "randomRedirect"
}
]
}
In index.ts of your functions (assuming TypeScript):
export const randomRedirect = functions.https.onRequest((_, res: functions.Response) => {
res.redirect(302, 'your desired URL');
});
Edit: You need to remove your index.html file for the URL to change in the address bar.
来源:https://stackoverflow.com/questions/58479587/how-can-i-redirect-my-homepage-to-a-random-url-through-firebase-hosting