是否可以将http用于某些请求,并将https用于其他请求,例如
http://i.mysite.com/
和
https://mysite.com/
感谢
答案 0 :(得分: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。