简体   繁体   中英

How do I set up a Rails page as a subdomain of another site?

We're trying to create pages in our Rails app that will eventually live on a subdomain of another partnering site. This would be like StatusPage , which allows users to create a status page with their account on the StatusPage site and then attach it to their own subdomain (eg status.usersite.com ).

For example, if we wanted one of our pages ( www.oursite.com/users/bobsplumbing ) to be a subdomain on another site ( ourservice.bobsplumbing.com ), how would we go about it?

If it's useful info, we use Heroku to host the Rails app and we also utilize Route 53 and Cloudflare.

From your example I understand that you want to have multiple web apps since that would be your customer domain and your page will redirect to that page.

You will be better off to do NGINX (or whatever you use) redirects since they are faster and will take less time, being cached by the browser after the initial load.

To answer your question you can add this code to your routes:

  sites = %w(bobsplumbing catsandboots)
  sites.each do |name|
    match "users/#{name}" => redirect("https://ourservice.#{name}.com")
  end

You can also have a look at apartment gem.

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