Pergunta

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:

http://example.com/

http://example.com/about

http://example.com/pricing

Rails App 2 (our real App) serves:

http://example.com/account

http://example.com/store

http://example.com/listings

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

Foi útil?

Solução

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.

Outras dicas

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.

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.

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

www.test1.mydomain.com

www.test2.mydomain.com

www.test3.mydomain.com

www.test4.mydomain.com

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"

http://tbaggery.com/2010/03/04/smack-a-ho-st.html

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

cheers

sameera

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top