简体   繁体   中英

Ruby on Rails http to https

New to all this, I hope I'll manage to explain things clearly. Thanks for your patience.

Question: Which would be the best approach to change ALL the urls from http to https in a Ruby on Rails existing website?

Context: An old website has all urls as http, it's being migrated to a new server (which will have an ssl certificate).

Steps undertaken so far: Some harcoded urls I changed manually. I've added 'default_url_options protocol: :https' on routes.rb, as suggested here Change protocol to https in all rails helpers I think 'config.force_ssl = true' wouldn't work, as it forces a redirect, but it doesn't change the urls, right?

But there are still some urls with the old http url. Not sure why, maybe it's really obvious, but whit my limited knowledge I don't know what else to check.

Versions are: Ruby 2.1.5 Rails 4.1.4

Thanks for your inputs!

您还可以更改DNS设置并通过https://www.cloudflare.com/ (它们内置HTTPS,对于非https请求,它们都严格重定向到https)

Thanks for your answers.

Finally, it was related to the assets (some images come from a cdn, and it wasn't properly configured).

Solution here: https://guides.rubyonrails.org/asset_pipeline.html#set-up-a-cdn-to-serve-static-assets "To set your asset host in Rails, you need to set config.action_controller.asset_host in config/environments/production.rb:"

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