0

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
4

1 に答える 1

0

私が使用しているドメインはさまざまなアプリ間で共有されているため、リクエストはApacheサーバーによって受信され、アプリサーバーに転送されるため、この方法でsslを強制しても機能しません。アプリはリクエストを「ローカル」と見なし、常に終了するためですhttp なので、リダイレクト ループに入ります。代わりに、サーバー レベルで https を適用します。

于 2012-10-29T19:36:36.390 に答える