Skip to content

Instantly share code, notes, and snippets.

@hannesl
Created August 21, 2014 09:52
Show Gist options
  • Select an option

  • Save hannesl/0ab2fb18fd21162ba11f to your computer and use it in GitHub Desktop.

Select an option

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.
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