Skip to content

Instantly share code, notes, and snippets.

@ashee
Created October 18, 2010 15:36
Show Gist options
  • Save ashee/632422 to your computer and use it in GitHub Desktop.
Save ashee/632422 to your computer and use it in GitHub Desktop.
SSL redirect in modrails
LoadModule passenger_module /Applications/MAMP/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /Applications/MAMP/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15
PassengerRuby /Applications/MAMP/ruby-enterprise-1.8.7-2010.02/bin/passenger_ruby
PassengerTempDir /Applications/MAMP/tmp/passenger
# PassengerUploadBufferDir /Applications/MAMP/tmp/passenger
PassengerLogLevel 3
# make a symlink from docroot to the public folder in your rails app
# cd /Applications/MAMP/htdoc; ln -s /wherever/your/appname/public appname
<VirtualHost *:8443>
ServerName cltp.localhost.edu
DocumentRoot "/Applications/MAMP/htdocs"
RequestHeader set X_FORWARDED_PROTO 'https'
<Directory /Applications/MAMP/htdocs>
AllowOverride all
Options -MultiViews
</Directory>
RailsEnv development
RailsBaseURI /cltp
</VirtualHost>
########################################################################################
In ApplicationController
proto = request.ssl? ? "https://" : "http://"
redirect_to :protocol => proto, :controller => "<controller_name_here>", :action => "<action_name_here>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment