Forum: Ruby on Rails Apache config: Two different rails apps using same domain na

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jake P. (Guest)
on 2006-05-17 22:29
(Received via mailing list)
The problem I'm solving here is that I have two different Rails
that uses the same domain name. One handles the www (e.g.
and is used as the main site, and the other handles the user subdomains
(e.g.. The DNS stuff and the Apache virtual
were all set up, the two rails apps are in place in the file system, and
proper .fcgi replacements were made in the .htaccess files. The
are the configuration details that I applied to test this scenario:

File System:
    Main application ( at /home/user/apps/mainsite
    User application ( at

Apache Configuration:

NameVirtualHost *:80
...[other stuff here (e.g FastCgi directives, and etc.)]..
<VirtualHost *:80>
    ServerAlias *
    DocumentRoot /home/user/apps/mainsite/public
    RewriteEngine On
    # If the host requested doesn't begin with www (or no subdomain),
rewrite to usersite directory
    RewriteCond %{HTTP_HOST} !^(www\.)?mycoolapp\.com? [NC]
    RewriteRule ^(.*)$ /home/user/apps/usersite/public/$1

I could see the main site ( -- it loads up fine. For
user site, the rails application error page is displayed, and the
entry in my apache error log:

mod_rewrite: maximum number of internal redirects reached. Assuming
configuration error. User 'RewriteOptions MaxRedirects' to increase the
limit if necessary.

My erroneous rewrite statements above is the problem. Anyone has ideas
there? Thanks.
Jake P. (Guest)
on 2006-05-19 17:43
(Received via mailing list)
I think I've solved this problem by skipping the rewrite stuff
Looking at the following Apache config:

# Main site vhost
<VirtualHost *:80>
    DocumentRoot /home/user/apps/mainsite/public

# User site vhost
<VirtualHost *:80>
    ServerAlias *
    DocumentRoot /home/user/apps/usersite/public

This split vhost configuration works. Requests to and are handled by the first one (main site), while all others
to the user site. The subdomain "user" is chosen arbirtarily, but the
important part is the ServerAlias that has the subdomain wildcard.

Also, along the way in your Rails application, some subdomains should be
reserved and be prevented from being created as usernames. Names like
ftp, admin, test, tmp, billing, and many others should not be used as
username and hence become subdomains of your site. They can be blocked
the data layer, controller, and even in the Apache configuration.

"Jake P." <removed_email_address@domain.invalid> wrote in
message news:e4fprb$e1e$removed_email_address@domain.invalid...
This topic is locked and can not be replied to.