Redirect 重定向自http://example.com 到https://example.mysite.com

Redirect 重定向自http://example.com 到https://example.mysite.com,redirect,ssl,https,ruby-on-rails-3.1,heroku,Redirect,Ssl,Https,Ruby On Rails 3.1,Heroku,这个问题有各种各样的排列,但我还没有找到正确的组合来回答我的特定问题 配置 Rails 3.1(允许我在我的应用程序控制器中使用强制ssl) 托管在Heroku Cedar上(因此我无法接触中间件) 我的SSL证书已注册到secure.example.com 我已经将force_ssl添加到我的ApplicationController中,如下所示: # file: controllers/application_controller.rb class ApplicationControll

这个问题有各种各样的排列,但我还没有找到正确的组合来回答我的特定问题

配置
  • Rails 3.1(允许我在我的
    应用程序控制器中使用
    强制ssl
  • 托管在Heroku Cedar上(因此我无法接触中间件)
  • 我的SSL证书已注册到
    secure.example.com
我已经将
force_ssl
添加到我的ApplicationController中,如下所示:

# file: controllers/application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery
  force_ssl
end
。。。但是我还没有充分研究重定向到和请求对象,以知道为
某物写什么…
。(我想确保它能处理查询参数等)

您应该看看——它本质上是Apache重写的,但是是Ruby格式的,在Heroku上可用


这将允许您创建各种机架级规则以及应发生的重定向等以及何时发生。

您可以通过执行以下操作重定向到其他主机名:

# file: controllers/application_controller.rb
class ApplicationController < ActionController::Base
  force_ssl :host => "secure.example.com"
end
#文件:controllers/application_controller.rb
类ApplicationController“secure.example.com”
结束

请参阅:有关更多信息

您可能还希望提供:protocol=>“https”参数。我在相关问题上看到了这个建议。
# file: controllers/application_controller.rb
class ApplicationController < ActionController::Base
  force_ssl :host => "secure.example.com"
end