从“mysite.herokuapp.com”重定向到“www.mysite.com” [英] Redirect from "mysite.herokuapp.com" to "www.mysite.com"

查看:151
本文介绍了从“mysite.herokuapp.com”重定向到“www.mysite.com”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何将heroku应用DNS配置为Godaddy域名?

我从GoDaddy购买了一个域名,说它是www.mysite.com,我在Heroku mysite.herokuapp.com上托管我的应用程序。当我点击mysite.herokuapp.com时,它应该重定向到www.mysite.com,我的网站从代码或类似网页到各种页面(例如myapp.herokuapp.com/users),但(mysite.herokuapp.com shuld不可访问)

解决方案

您应该在您的Rails应用程序中执行此操作。

创建一个检查 HTTP_HOST 变量的Rack中间件。
如果该值与 www.mysite.com 不匹配,则发送重定向状态码并将用户重定向到正确的路径。



以下是一些您可以从中获得灵感的例子


Possible Duplicate:
How to configure heroku application DNS to Godaddy Domain?

I purchased a domain from GoDaddy, say it's www.mysite.com, and I am hosting my app on Heroku mysite.herokuapp.com. When I click on mysite.herokuapp.com it should redirect-to www.mysite.com, my site to various pages (e.g. myapp.herokuapp.com/users)from code or similar but (mysite.herokuapp.com shuld not be accessible)

解决方案

You should do it inside your Rails application.

Create a Rack middleware that inspects the HTTP_HOST variable. If the value doesn't match www.mysite.com, then send a redirect status code and redirect the user to the right path.

Here's a few examples you can start from to get an idea

这篇关于从“mysite.herokuapp.com”重定向到“www.mysite.com”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆