从子域重定向到根域未按预期工作

Redirect from subdomain to root domain not working as expected

我目前正在 rails 项目的 ruby 上工作,我正在用 jquery 做一些原始的 javascript。我想从 localhost:3000/home 重定向我的根域 localhost:3000。

要实现这一点,我必须使用以下代码:

window.location.replace('localhost:3000');

这不会让我回到我的主页,而是回到主页 localhost:3000/home/ 或者什么都不做。

但是我尝试了一个不同的域,whosebug.com,这很有效

window.location.replace('http://whosebug.com/');

url 有效,所以我不知道重定向到本地主机可能有什么问题。这是路由的安全问题,还是与我在本地主机上工作有关?对这种方式的任何帮助将不胜感激。谢谢!

您的 url 中缺少 "http://"。

window.location.replace('http://localhost:3000');