I have a rails app that gives users a subdomain for their site. Users can then point their own domain to this sub domain to make it look like their own site.
When i user enters a domain name into my app i need to redirect any future requests to there subdomain url on my app to their own domain, also passing the path eg company_site.hosted_site.com/pages/about_us redirects to http://www.company_site.com/pages/about_us.
Does anyone know how to do this in rails 3 ?
I cant so it using apache rules as need to hit the database to get redirect url and also dont want to change the conf file per users/subdomain.
Anyone done this ? ssems might be best done in rack middleware ? any ideas?
thanks alot
Rick
A simple way is to do this in a
before_filterblock for ApplicationController so that all actions are affected by it:Customer would be your record where you store the assigned
subdomainand an optional customdomainthat they will be redirected to if it is specified.In your Customer record you might have something like this as a helper method: