How to handle multiple hostnames #183

runtimerevolution opened this Issue May 4, 2012 · 9 comments


None yet

3 participants



I'm trying to make a CMS site work on two domains ( and In terms of DNS, everything is setup properly. However, on CMS, I can only setup one of them as the hostname.

I specified and it worked properly while only a single site existed in CMS. When I added a second site, it only works for the exact hostname configured.

Is there a way around this ?


GBH commented May 4, 2012

This is a pretty common thing. You don't really do this within rails application. You need to set up a permanent redirect on the webserver level. Like for apache for instance:


RewriteEngine On
RewriteCond %{HTTP_HOST}$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

... something like that. There's also a setting in cms to use host aliases, but it's mostly a convenience thing during development when people have different setups... like localhost vs


I would be able to do that on apache, but this is a very small setup, so we're using webrick.

I imagine you use the hostname setting to facilitate virtual hosting, in that case wouldn't it make sense to be able to specify more than one ?

pietere commented May 11, 2012

I personally would say this should be possible in the rails app itself. 2 domains pointing to 1 app should be working both.

pietere commented May 12, 2012

@GBH , just to know, is there any functional or technical reason to not allow more then one host for 1 site? If not, probably we will develop some code to add this functionality

GBH commented May 14, 2012

What you're looking for already exists. Take a look inside initializer:

# Site aliases, if you want to have aliases for your site. Good for harmonizing
# production env with dev/testing envs.
# e.g. config.site_aliases = {'' => 'host.inv', '' => ['', '']}
# Default is nil (not used)
# config.hostname_aliases = nil

Ok, thanks for the info, I'll give it a try

pietere commented May 14, 2012

I'm not sure if this is exaclty the desired behaviour. It seems to redirect to the alias. Goal is that the same site (rails app) can run under different domains.

Like,,, are all pointing to the same app on the same server, and they just work.

Trying this with mexican sofa, will give a "Site not found" error, or, if using aliases, it will redirect to the main site.

pietere commented May 15, 2012

My mistake...

This seems to work fine in production. When I tested it locally, didn't work however. It does a forward in development mode, but it works in production mode. So all fine here, the aliases work as they should!

@GBH GBH closed this May 24, 2012

This worked fine for us too. However, config.site_aliases no longer works, I had to use config.hostname_aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment