views:

65

answers:

1

I want my Sinatra app to allow users to create an account and access it via a subdomain (i.e. your-account.myapp.com).

I found this to extract subdomains (http://gist.github.com/55784#file_subdomains.rb) but I'm having a hard time implementing it.

Any ideas?

I have an Account model (datamapper) with a field called account name, which should be the subdomain.

Thanks!

A: 

What you're trying to accomplish is called "wildcard subdomains", which is very simple to implement.

a. Provide a wildcard record for your DNS server:

*.example.com.    IN    A    1.2.3.4 (this is your web server IP address)

b. In Apache, create a virtual server that accepts connections for any subdomain entered:

<VirtualHost 1.2.3.4>
  DocumentRoot /usr/www/htdocs
  ServerName www.example.com
  ServerAlias *.example.com
</VirtualHost>
Paul