I have an HTTP and HTTPS version of my Ruby on Rails running, and if someone accesses through the HTTP one, I want to automatically reload the HTTPS version.
I have done this before on Apache with .httaccess. How can I do it on Rails?
Thanks
在您的production.rb文件中(或您要强制ssl的任何环境中)添加
config.force_ssl = true
You can also achieve that by:
class ApplicationController < ActionController::Base
force_ssl if: :ssl_enabled?
private
def ssl_enabled?
%w(staging production).include?(Rails.env)
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.