我的目标是将基本URL (mydomain.com/)重定向到另一个网站。我正在使用Firebase主机,并且已经在重定向中尝试了Regex功能来实现这一点。我在重定向时跟踪了这个基本的文档,但没有成功。
我的目标是:
我发现这可以在JavaScript中实现,但是因为我对Firebase很陌生,所以我不知道如何使用它。(也许通过使用云函数?)
if (window.location.pathname === '/') {
//redirect to otherdomain.com
} 我的守则:
{
"hosting": {
...
"redirects": [
{
"regex": "^/$",
"destination": "otherdomain.com",
"type": 301
}
],
...
}
}问题是,此代码将每个URL重定向到新域。我的下一个想法是使用"regex": "^(?!.*[/].+)",但不支持?!。
发布于 2020-10-16 13:19:02
我不知道该怎么做。我知道很多域名注册人允许你这样做。打开您的域名注册员,并设置一个URL重定向或URL转发,并设置它使用相同的URL路径。如果这不是您的域名注册程序中的一个选项,您可能需要查看google域。https://domains.google.com。我知道注册员允许你这么做,我以前也这么做过。
发布于 2020-10-17 14:59:57
我的解决方案:firebase.json
{
"hosting": {
...
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
...
}
}index.html
<body>
...
<script>
if(window.location.href === "mydomain.com/") {
window.location.href = "www.otherdomain.com";
}
</script>
...
</body>在https://前面加上mydomain.com/和www.otherdomain.com
https://stackoverflow.com/questions/64379009
复制相似问题