Rails:重定向到特定域...但不要覆盖 SSL? [英] Rails: Redirect to specific domain... but don't override SSL?

查看:45
本文介绍了Rails:重定向到特定域...但不要覆盖 SSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将 Rails (3.0.9) 应用程序从一个域移动到另一个域.Heroku 建议在应用程序控制器中使用 before_filter 以确保每个人都进入新域,如下所示:

So, I'm moving my rails (3.0.9) app from one domain to another. Heroku suggests using a before_filter in the application controller to make sure that everyone ends up on the new domain, like so:

before_filter :ensure_domain if Rails.env.production?

APP_DOMAIN = 'www.newdomain.com'

def ensure_domain
  if request.env['HTTP_HOST'] != APP_DOMAIN
    redirect_to "http://#{APP_DOMAIN}", :status => 301
  end
end

但是,在某些控制器视图上,我使用了 ssl_requirement,我相信它会做同样的事情,但会强制使用 ssl 协议.

However, on certain controller views I'm using ssl_requirement, which I believe does the same thing but forces ssl protocol.

我对请求处理和所有爵士乐并不那么聪明.我的问题是,这两个是否会创建一个无限循环,其中 SLL 尝试重定向到 https,而 before 过滤器尝试将其放回 http?

I'm not that smart about request handling and all that jazz. My question is, are these two going to create an infinite loop, where SLL tries to redirect to https and the before filter tries to put it back to http?

你会如何解决这个问题?

How would you solve this issue?

推荐答案

只要尊重当前协议:

redirect_to("#{request.protocol}#{APP_DOMAIN}", :status => 301)

这篇关于Rails:重定向到特定域...但不要覆盖 SSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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