简体   繁体   English

如果未访问第一个域,则将一个域重定向到另一个域

[英]Redirect one domain to another if first domain wasn't visited

I have two apps on Heroku. 我在Heroku上有两个应用程序。 I ONLY want people to access the second app, if they have already visited the first app. 我只希望人们访问过第二个应用程序(如果他们已经访问了第一个应用程序)。 Meaning if you went directly to app2.herokuapp.com it would redirect you to app1.herokuapp.com. 这意味着,如果您直接转到app2.herokuapp.com,它将把您重定向到app1.herokuapp.com。 But if you came from app1.herokuapp.com then it would NOT redirect when you got to app2.herokuapp.com 但是,如果您来自app1.herokuapp.com,那么当您进入app2.herokuapp.com时它不会重定向

One more thing, I am only looking to redirect people that get to the naked URL. 还有一件事,我只希望将重定向到裸URL的人员重定向。 FI they go to an internal page, I don't want it to redirect. FI他们转到内部页面,我不希望它重定向。

Is there a way to do this directly in heroku? 有没有办法直接在heroku中做到这一点? If not what is the best way to do this? 如果不是,最好的方法是什么?

The easiest way would be to use cookie/session and from your applications handle the logic. 最简单的方法是使用cookie /会话,并从您的应用程序处理逻辑。

Just in case also some CDN's allow custom rules based on cookies so this could be useful for a serverless setup, based on the site the user visit you set a cookie and once the "rule/condition" decides where to redirect the requests. 以防万一某些CDN允许基于cookie的自定义规则,因此这对于无服务器设置很有用,它基于用户访问的站点设置cookie,并且一旦“规则/条件”决定了重定向请求的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM