On 26 Jul 2007, at 23:07, Armand du Plessis wrote:
Thanks Jacob. If I want to keep the code clean without checking
subdomains everywhere i think I’ll have to look at the apache
rewriting then. Was kinda hoping I could skip that part and that
there’s some subdomain magic in the routes configuration that I was
Actually, that’s not what Jacob means.
It’s quite simple actually: if you want to use one application with
one database, but identify customer accounts with a subdomain, you
have to pass the subdomain to Rails and let it either store the
company in a session or use an application-wide before_filter to look
up the subdomain. Using a subdomain shifts the emphasis from your
website url to the customer, he gets the feeling it’s his private
space (or at least that’s how i like to look at it) and it reads a
You could use Apache rewrite to rewrite the url
mycustomer.mydomain.com to mydomain.com/mycustomer, but it doesn’t
make a difference if you’re search for the customer in the database
There are two plugins I’ve used in the past for subdomain based
routing: account_domain and request_routing, both work fine. Don’t
forget to add ServerAlias *.mydomain.com in your virtual host
definition as well as add the wildcard domain to your dns.
Apache rewrites can be very useful, e.g. if you want to run a
separate mongrel for some or all customers. It has quite a few other
uses too, but these are out of the scope of this thread.
Peter De Berdt