How can I redirect my homepage to a random url through firebase hosting?

孤者浪人 提交于 2020-01-24 20:28:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!