views:

68

answers:

2

Hi, I'm currently developing a user facing web application that gives each new user their own subdomain on the site, which is fine (using subdomain_fu), but is there a way to let a user map their own domain to this subdomain?

I know how to do this manually through SSH-ing into the server and editing the Apache Vhosts file by hand, but is there a way to do this automatically so that a user simply enters their domain into a box on the site (obviously they'd have to change their own DNS elsewhere)?

I'm using Ruby 1.8 and Rails 2.3.3 on top of Apache.

Essentially letting;

http://user.application.com/article-1

be accessed from

http://userdomain.com/article-1

Thanks for any help!

A: 

I assume this is just one application that you want users to map different domain names to, right? You shouldn't need to use virtual hosting at all, since all requests will go to the same Rails app, regardless of domain name. If you are using virtual hosting, then the default virtual host (the one that handles http://1.2.3.4 if user.application.com resolved to 1.2.3.4) needs to be your Rails app.

pjb3
Yes one application, that users can assign their own domain to their own subdomain.We're using Virtual Hosts, so how would we set it up?Pointing a domain to the IP address of the application simply pops up with "It Works!"Thanks.
Steve F
The default virtual hosts should be the first one that gets loaded. I don't know how you have Apache configured, but try to figure where the "It Works!" page is and that's the one it's using as the default
pjb3
+1  A: 

Your users should be able to set up a CNAME record for their domain pointing to your domain, e.g.

userdomain.com.  CNAME  user.application.com.

and then let your app know that they want to use userdomain.com as their hostname. I don't think you will have to change your vhost settings because your server will see the request for user.application.com, but test this by setting up a CNAME of your own to be sure.

In your app you will then need to look at the hostname and if it contains application.com you do as you do now, but if it doesn't you check to see if there's a user who has set that domain as theirs.

Theo
Rather then say the same thing as Theo here, use CNAME. Places like Shopify.com use this strategy/technique with great success. I've yet to see a step by step instructional tutorial for this however.
pjammer
I can't get this to work, I can get the domain pointed at the server itself, but it just displays the "It Works!" screen. I'm assuming it's got something to do with the final step as I'm not sure what to do. Thanks.
Steve F