#284 ✓resolved
John Small

Single site mode should not search on hostname

Reported by John Small | April 17th, 2009 @ 12:44 PM

Given that Site.multi_sites_enabled == false And I have a site www.mysite.com Then I want mysite.com and even localhost to get me through to the single site listed in the sites table.

Currently the CMS does a search on hostname even if Site.multi_sites_enabled == false, which can be irritating if you potentially have users visiting the site without the www. on the front of the hostname or if you want to mess around a bit using localhost to see what's going on.

Comments and changes to this ticket

  • Priit Tamboom

    Priit Tamboom April 20th, 2009 @ 08:46 AM

    I just copy-paste from the list: http://groups.google.com/group/a...

    Meanwhile I'm using apache redirection:

    <VirtualHost *>
      ServerName www.example.com
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
      RewriteRule ^(.*)$ http://%1$1 [R=301,L]
    <VirtualHost *>
      ServerName example.com
  • John Small

    John Small May 4th, 2009 @ 10:41 AM

    This is also irritating when running tests. The Rails test runners use www.example.com as host but if you want to look at the pages that are being produced in the test rig you'd want to see localhost:3000. You can get round this by setting up various redirections but it shouldn't really be required. If the site is set up for single host then just get the first record from the sites table irrespective of host name.

    I've tried to work out where the code needs to be amended and it's not one place. I was hoping that changing Site.find_by_host! to search for the first record iff Site.multi_sites_enabled == false would do the trick. But it doesn't. Changing the operation of Site.find_by_host! so that it doesn't find by host makes me cringe, it was a little experiment, to work out the flow of control, I would never have done that for real!

    What happens is that the changed version of Site.find_by_host! does get the first record, but then the rest of the code still goes off into "login" if the hostname you're using to access Adva isn't the hostname in the site record. So there are other places where it does a search on hostname (which I can see in my logs).

    I believe that simple things should be implemented simply. A request for the root should be redirected to the site root without a detour through the administrative controllers. So I think the best way to implement this would be to change the routes on start up so that if and only if Site.multi_sites_enable == false && Site.count == 1 then "/" goes directly to the visible display of the site.

  • Marko Seppä

    Marko Seppä June 19th, 2009 @ 10:32 AM

    • State changed from “new” to “open”

    Added to product backlog.

  • Marko Seppä

    Marko Seppä August 4th, 2009 @ 10:29 AM

    Hi Jon,

    Isn't this adding more complexity by introducing this single-site only one site installed scenario? Currently adva-cms site finding works same way on every scenario, single site with one site and multi site with many sites.

    I really think the www and without www is a thing you have to do on your web server configuration and it is not a responsibility of adva-cms.

    I am not sure about what kind of testing scenario you are talking about where this is a problem.

    -- Marko

  • Micah Geisel

    Micah Geisel August 5th, 2009 @ 12:56 AM

    Hi guys,

    I would also like to see adva simply use the first site if multi_sites_enable is false. Our use case is as follows:
    a site has three hostnames: sitename.local on all our development machines, sitename.mycompany.com for our staging machine, and www.sitename.com on the production machine. i have cap + rake tasks set up to clone the database from production (or staging) to any development machine. currently, i have to modify the host name in the database everytime i clone.

  • John Small

    John Small August 5th, 2009 @ 10:31 AM


    This is my problem exactly. It's a real PIN to have to keep editing the hostname on the one site record when moving databases around from dev to staging to production.

    I made a temporary workaround by changing find_by_host_name to always get the first record if there's only one site. But in some cases that doesn't work, like when you're editing the site.

    While I was doing that I noticed that a simple GET request to "/" goes through layers of indirection and around_filters just to get the index page. I think that simple requests should be handled simply and you can't get much simpler than a GET '/' on a single site.

    There seems to be a lot of areas in ADVA where things are more complicated than they need to be, or don't do what you expect them to. I was surprised to find that the flash didn't do what it normally does, so I changed the code so that it did. Then I found that keeping sessions in the DB made things blow up. I've not fiddled with that because life is short.

    John Small

  • Marko Seppä

    Marko Seppä August 5th, 2009 @ 11:09 AM

    Hi John and Micah,

    altough I have done many deployments with adva-cms I have not been moving the databases around like this - so I think this is the only scenario where the finding of a site with host is a problem. I would say that this is a edge case and I am not sure should we add this special rule to adva-cms, it only solves an edge case and adds a small amount of complexity to standard flow of adva-cms site finding.

    Also it does not solve a problem when you are handling databases like this with multi-site installation.

    John, could you add the things you find confusing or more complicated than needed to our mailing-list - so we could have a discussion about them and this way improve the areas that are bad. adva-cms is still on very early stages and we would like to get all the info about what we could improve and do better as possible.

    I also create a topic for this on mailing list to get more input in this.

    -- Marko

  • Casper Fabricius

    Casper Fabricius August 6th, 2009 @ 10:15 AM

    I have an Adva-based application that runs several different languages based on the domain, since this is generally what SEO-experts seems to recommend for multi-language sites. I have monkey-patched Adva to always load the first - and my case only - site by adding this code the lib-folder:


    • and patching in into the Site model in an initializer like this:

    Rails.configuration.to_prepare do
    Site.send(:include, SiteExtension) end

    It's a hack, but it seems to work for now - as long as Adva sticks to loading the site through the find_by_host method ;)

    I think it as very valid and not too uncommon scenario to have a single application that responds to multiple domains, so I agree that you should be able to specify more than one domain per site.

  • Marko Seppä

    Marko Seppä August 17th, 2009 @ 12:55 PM

    • State changed from “open” to “resolved”


    I just committed a fix for this. So when you are running on single site mode with only one site existing the Site.find_by_host! method returns the first site.

    Multi domains are a subject of a new ticket.

    -- Marko

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<p>Cutting edge cms, blog, wiki, forum ... plattform.</p>

<p>Find the code on <a href="http://github.com/svenfuchs/adva_cms/tree/master">GitHub: adva cms</a></p>

<p>Part of the business application framework <a href="http://www.advabest.org/">adva best</a>.</p>