1

Possible Duplicate:
Why am I getting infinite redirect loop with force_ssl in my Rails app?

I have this in my application controller:

before_filter :redirect_to_ssl!

def redirect_to_ssl!
  redirect_to "https://" + request.host + request.fullpath if !request.ssl? && Rails.env.production?
end

However, when I view my site (in production mode) with https:// it goes in a redirect loop... It appears that request.ssl? returns false even though I am using the https protocol..... Now, when I view my site, the browser does warn me that my ssl certificate can't be verified-- I am wondering if that is why request.ssl? returns false? What is a good workaround? Should I just check to see if the request.protocol == "https://" ?

Community
  • 1
  • 1
patrick
  • 9,290
  • 13
  • 61
  • 112

1 Answers1

4

Don't do this in the controller.

Instead, in config/environments/production.rb (and whichever other environments you want to use SSL), do this:

config.force_ssl = true

Read more info on configuring Rails 3 to use HTTPS.

GladstoneKeep
  • 3,832
  • 2
  • 26
  • 38