0

是否可以将 http 用于某些请求,将 https 用于一个 Rails 服务器的其他请求,例如

http://i.mysite.com/

https://mysite.com/

谢谢

4

1 回答 1

1

是的:

before_filter :https_redirect

def https_redirect
  if request.ssl? && !use_https? || !request.ssl? && use_https?
    protocol = request.ssl? ? "http" : "https"
    flash.keep
    redirect_to protocol: "#{protocol}://", status: :moved_permanently
  end
end

def use_https?
  controller_name == "abc"
end

(我从某个地方获取此代码,我不记得了,所以我不能给出学分......但我在一个项目中使用它并且它有效)。

更新:我从 RailsCasts 获取代码,哈哈,感谢 Ryan Bates。

于 2013-04-12T02:46:56.547 回答