views:

45

answers:

1

I have a rails app where customers sign up and get a custom subdomain site/url like this:

  • customer1.myapp.com
  • customer2.myapp.com
  • customer3.myapp.com

What are the steps I need to take to allow a customer to use their own registered domain name such that their domain points to my app?

So, in the example above, if "customer1" owns "customer1.com" - how can I setup my app so that any requests to "customer1.com" are sent to "customer1.myapp.com"? Also, what would my customer need to do on his end?

Thanks.

+1  A: 

Your customer is going to need to set up DNS For their domain to point it, or part of it, to your address. This can be tricky to coordinate, especially if the address of the server you're hosting the service on can change from time to time. It's a lot easier to route a customer's subdomain to your subdomain.

You'll also need a lookup table that maps a customer's domain to a customer's account. That's typically expressed as something like this:

before_filter :load_customer_from_host

def load_customer_from_host
  # Strip "www." from host name to search only by domain.
  hostname = request.host.sub(/^www\./, '')

  @customer = Customer.find_by_host!(hostname)
rescue ActiveRecord::RecordNotFound
  render(:partial => 'customer_not_found', :layout => 'application', :status => :not_found)
end

That presumes you have a Customer model with a 'host' field set with something like 'customer1.myapp.com' or 'customer1.com', whatever matches the host field.

When you set up your app, you will need to have a virtual host configuration that responds to all arbitrary domain names. This is easy to do if it is the only site hosted, since that is the default behaviour. If you're doing this on shared hosting you may have to configure an alias for each customer domain specifically, which can be a nuisance.

tadman