Take the 2-minute tour ×

This is kind of weird but I'd like to serve multiple websites on the same domain. If possible, we want to avoid subdomains to keep urls simple for our users - no need for them to know it's two separate apps. This is purely for keeping the code bases separate. Any ideas?

For example:

Rails App 1 (Refinery CMS) serves:




Rails App 2 (our real App) serves:




We use ruby 1.9.2, ruby on rails, refinery cms, apache and passenger.

share|improve this question
add comment

4 Answers

up vote 9 down vote accepted

If you're using Passenger, check out the Deploying to a sub URI portion of the manual - it's quite simple to set up an app on a sub-URI. You may need to set config.action_controller.relative_url_root in your app configuration, as well.

Edit: I misread the question; not one app per URI, but one app serving some (but not all) endpoints. This is actually moderately easy to do with some basic rewrites, as well.

Deploy your Rails app to, let's say, /railsapp (but without setting relative_url_root). Now, in .htaccess:

RewriteRule ^account/(.*)$ railsapp/account/$1 [L]

This will internally remap /account/* to /railsapp/account/*, so as long as you set up a rewrite per path your Rails app handles, it should work fine.

share|improve this answer
I think I get it. Will give it a try. Thanks! –  chrishomer Dec 30 '10 at 2:09
add comment

Subdomains make it easier (thus why most sites have shop.example.com), but you could probably use rewrite rules with name based virtual host routing. How exactly to do that I'm not sure. More of a Apache rewrite question for SuperUser.

A word of warning if you are using SSL you might have issues arise.

share|improve this answer
add comment

You could set it up to first hit one app where you expect most URLs would work and if it 404s you could instruct it to try the other app next, though this will be slower than routing per route but it will work without having to hardcode a route for every page that is created on say, Refinery CMS.

share|improve this answer
add comment

Currently I'm also working on a same kind of CMS. In my case also I need multiple sub domains, like





here is what I did

in rails 3 (if you are on rails3) you can get the sub domain by using request object. (If you are on rails 2.x you can use sub domain_fu plugin)

In my case I have used a before filter to get the sub domain, after that I load the site according to the sub domain

For development use the following public domain "lvh.me"


this was very useful for me http://railscasts.com/episodes/221-subdomains-in-rails-3

let users have their domains forwarded to your subdomain (with masking)

ex : www.clientdomain.com --> http://client.mydomain.com

hope this helps



share|improve this answer
Poster specifically asked for hosting without sub domains. –  Ciryon May 11 '13 at 14:02
add comment

Your Answer


