Created
March 17, 2011 17:22
-
-
Save teeparham/874742 to your computer and use it in GitHub Desktop.
Rails 3 routes with SSL
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
SSL_PROTOCOL = 'http' |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to use 'http://' and 'https://' for the protocol constraints.