Subdomains and rails

Posted in Uncategorized by elisehuard on October 8, 2008

We’re working on a system using subdomains as an account key.  This common, but still cool feature allows people to have their own virtual webspace, adding their own subdomain, say

elise.ilikethissite.org, or coolboots.myclub.net

This is relatively easy to do in Rails itself – the plugin subdomain-fu (railscast here) makes it almost childs play.
So the problem is not rails, but setting up your development environment to be able to work with it.

  • web server : your web server has to accept wildcard aliases for all subdomains. On most modern servers this is relatively easy, i know Apache (ServerAlias), lighttpd (regular expression for the $HTTP[‘host’]) allow this no problem, and this should be the case for other modern web servers.
  • DNS : if you don’t fix this, DNS servers outside your machine will try to make sense of the address, which is of course not what you want. On a mac OS X Leopard in its original state it’s not possible to use wildcards in the /etc/hosts (at least it will not listen). The life saver here was the following link : setting up your own DNS server locally on your machine.
  • (Update) A last gotcha: sessions.  If you want your users to be logged in and logged out throughout your site (regardless of subdomains), you could use a small amendement as in this link.  However, that may not be what you need – sometimes you want to keep the worlds separated, so that’s up to you.

And you can have your own cool fake domain names to play with in development !
Walking on the shoulders of giants, don’t you love it …


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: