How do I allow users to use custom domains?
April 4, 2008 2:18 PM   RSS feed for this thread Subscribe

What do I need to do to allow users to point their domains to my web service?

Let's take tumblr.com as an example. They're a blogging type service, and they allow users to point their custom domains to their tumbler account, the instructions for a user to do so are available here: Using a custom domain name.

If I were to want to do the same with my web application, what's required on my end to facilitate users using custom domains?
posted by jcruden to computers & internet (6 comments total) 4 users marked this as a favorite
Depends on your application. What does it do? What should happen when someone visits the customer's domain? Do you already have a web page for the customer (e.g. customername.yourname.com or yourname.com/customername) and you just want to change its address to the customer's name?
posted by winston at 2:27 PM on April 4


It's pretty easy. You just need to setup your http server to send requests from any domain to your application (ruby, php, whatever). That means you need to have it on either a VPS or a dedicated machine. No shared hosts allowed.

This assumes you're already using something.example.com subdomains, but here's how it's done in ruby:

Once the request comes in, you want to check the domain name. If it's not your own domain (example.com) or localhost (for testing purposes), you need to lookup the context just as you would with subdomains, but do it with the host information not the subdomain.

def find_group_from_subdomain
  if request.domain != 'localhost.com' || request.domain != 'example.com'
    @group = Group.find_by_custom_domain(request.domain)
  else
    @group = Group.find_by_subdomain(request.subdomains(tld_length).first)
  end

  redirect_to(no_group_url) if @group.blank?
end

Ping me on AIM (same username) if you have questions or need more help.
posted by jdgdotnet at 2:43 PM on April 4


Forgot to mention, they also obviously need to setup their domain name to point to your application.

Best practice here is to point it using a CNAME to their subdomain on your site. So to take your Tumblr example a bit further, the customer would add a CNAME entry to their dns that points blog.example.com to whatever.tumblr.com.

You want to use CNAME's rather than IP addresses, in case your IP address ever changes. By using CNAME's, you just have to update your own DNS records. If the customers are pointing their domains to your IP address, and you have to change your IP, then all of your customers have to update their DNS records too. It would make migration extremely painful later on.

Tumblr specifically gives you their IP address to point your record to. Not sure if that's just an oversight or if they know something I don't know, but the above is the way I've always done it for the reason listed. :)
posted by jdgdotnet at 2:47 PM on April 4


Okay, so that's pretty much really simple.

My mind was envisioning complicated DNS entries, which is an area of understanding I've yet to acquire.

Thanks!
posted by jcruden at 2:49 PM on April 4


CNAME it is, in that case!

Thanks again.
posted by jcruden at 2:51 PM on April 4


You can do what I do with metafilter, and make a CNAME of * an alias for the main server. Most DNS setups can handle the * wildcard. Try it with metafilter, anythingatallyoucanthinkof.metafilter.com will open www.metafilter.com (I rewrite the URL now, since Google used to have hundreds of subdomains indexed).
posted by mathowie at 11:46 PM on April 4


« Older How can I set an out of office...   |   Looking for recommendations fo... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
What are some good blogs/sites that are like... February 21, 2008
What are the most intellectually stimulating... November 20, 2007
Help picking web page applications please ! September 26, 2006
How to get more people to use my web app? February 5, 2006
PortalFilter: For a new website, would you go with... February 8, 2005