Created
August 21, 2014 09:52
-
-
Save hannesl/0ab2fb18fd21162ba11f to your computer and use it in GitHub Desktop.
Use temporary (302) redirects to force ssl in Ruby on Rails, rather than the standard configuration approach which uses permanent (301) redirects. This is useful when you may want to switch to a non-ssl environment later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| ... | |
| # Redirect all requests to SSL. We use this rather than config.force_ssl since | |
| # we want to use temporary rather than permanent redirects. | |
| if Rails.env.production? | |
| before_filter do |controller| | |
| controller.force_ssl_redirect({:status => :found}) # 302: Moved temporarily | |
| end | |
| end | |
| ... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment