I'm trying to force all urls generated by my controller to be "https" and redirecting to https otherwise. I tried the method explained in this blog and the one suggested by Olly here and I'm getting this error if I try to access my application:
This webpage has a redirect loop
The webpage at https://'example.com' has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Clearing the cookie doesn't help. Why is it going into a loop? I made sure to run the code under condition that request.ssl is false. I'm using Rails 2.3.10. So here is what I tried, in my application controller I added:
url_for unless (Rails.env.test? || Rails.env.development?)
def default_url_options(options)
{ :only_path => false, :protocol => 'https' } unless (Rails.env.test? || Rails.env.development?)
end
I also tried
def redirect_to_https
redirect_to :protocol => "https://" unless (request.ssl? || Rails.env.test? || Rails.env.development? || local_request?)
end