从“mysite.herokuapp.com”重定向到“www.mysite.com”

编程入门 行业动态 更新时间:2024-10-23 17:34:13
本文介绍了从“mysite.herokuapp”重定向到“www.mysite”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 如何将heroku应用DNS配置为Godaddy域名?

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

解决方案

您应该在您的Rails应用程序中执行此操作。 创建一个检查 HTTP_HOST 变量的Rack中间件。 如果该值与 www.mysite 不匹配,则发送重定向状态码并将用户重定向到正确的路径。

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

  • b $ b
  • github/stjhimy/rack-www

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

I purchased a domain from GoDaddy, say it's www.mysite, and I am hosting my app on Heroku mysite.herokuapp. When I click on mysite.herokuapp it should redirect-to www.mysite, my site to various pages (e.g. myapp.herokuapp/users)from code or similar but (mysite.herokuapp 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, 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

  • How to redirect without www using Rails 3 / Rack?
  • github/stjhimy/rack-www

更多推荐

从“mysite.herokuapp.com”重定向到“www.mysite.com”

本文发布于:2023-11-01 11:58:12,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   mysite   herokuapp   www

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!