简体   繁体   English

如何将Rails页面设置为另一个站点的子域?

[英]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. 我们正在尝试在Rails应用中创建页面,这些页面最终将位于另一个合作网站的子域中。 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 ). 这类似于StatusPage ,它允许用户使用其在StatusPage网站上的帐户创建状态页,然后将其附加到自己的子域(例如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? 例如,如果我们希望其中一个页面( www.oursite.com/users/bobsplumbing )成为另一个站点( ourservice.bobsplumbing.com )的子域,我们将如何处理?

If it's useful info, we use Heroku to host the Rails app and we also utilize Route 53 and Cloudflare. 如果有用的信息,我们将使用Heroku托管Rails应用程序,并且还将使用Route 53和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. 从您的示例中可以理解,您希望拥有多个Web应用程序,因为这将是您的客户域,并且您的页面将重定向到该页面。

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. 您最好进行NGINX(或您使用的任何方法)重定向,因为它们速度更快且花费的时间更少,并且会在初始加载后被浏览器缓存。

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. 您也可以看看公寓的宝石。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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