简体   繁体   中英

Redirecting root domain to www on Heroku Hostname based SSL

I'm trying to redirect my root domain: http://[sitename].com to https://www.[sitename].com

  • Backend is rails on heroku with a Hostname Base SSL.

  • My domain is registered on GoDaddy.

And, here is what I've tried:

  • In my ApplicationController, I have a before_filter called redirect_to_https. And the contents of that are:

     def redirect_to_https puts "In Redirect" redirect_to "https://www.[sitename].com#{request.fullpath}" unless request.ssl? || !Rails.env.production? end 

When I browse to the root domain of the website, I do not see the "In redirect" in the logs. So, clearly that redirect is not actually working.

Any ideas?

I would look at Rack-rewrite , it's a much more efficient lower level library that does all this sort of thing really well. Alternatively, roll your own:

http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM