Rails:重定向到特定域...但不要覆盖 SSL?

编程入门 行业动态 更新时间:2024-10-15 20:24:44
本文介绍了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' def ensure_domain if request.env['HTTP_HOST'] != APP_DOMAIN redirect_to "#{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?

本文发布于:2023-11-01 13:30:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549453.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   Rails   SSL

发布评论

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

>www.elefans.com

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