Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created March 17, 2011 17:22
Show Gist options
  • Save teeparham/874742 to your computer and use it in GitHub Desktop.
Save teeparham/874742 to your computer and use it in GitHub Desktop.
Rails 3 routes with SSL
SSL_PROTOCOL = 'http'
SSL_PROTOCOL ||= 'https'
YourAppName::Application.routes.draw do
constraints :protocol => SSL_PROTOCOL do
# put your SSL routes here
# resources :secrets
# ... etc
# redirect anything that did not match to http
unless SSL_PROTOCOL == 'http' # development
match '(*path)', :to => redirect { |_,request| "http://#{request.host_with_port}#{request.fullpath}" }
end
end
# put your non-SSL routes here
# resources :monkeys
# ... etc
# redirect unmatched requests that should be https but came in as http to https
# match 'secrets(/*path)', :to => redirect { |_, request| "https://#{request.host_with_port}#{request.fullpath}" }
end
@korny
Copy link

korny commented Feb 28, 2012

I had to use 'http://' and 'https://' for the protocol constraints.

@teeparham
Copy link
Author

Use force_ssl now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment