private RootFolder resolve(String host) {
        if (host.contains(":")) {
            host = host.substring(0, host.indexOf(":"));
        }
        System.out.println("resolve: " + host);
        Session session = SessionManager.session();
        String primaryDomainSuffix = "." + primaryDomain;
        if (host.endsWith(primaryDomainSuffix)) {
            String subdomain = Utils.stripSuffix(host, primaryDomainSuffix);
            System.out.println("subdoman: " + subdomain);
            // If starts with admin. then look for an organisation, will go to admin console
            if (subdomain.startsWith("admin.")) {
                String orgName = Utils.stripPrefix(subdomain, "admin.");
                System.out.println("look for org: " + orgName);
                Organisation org = Organisation.findByOrgId(orgName, session);
                if (org != null) {
                    System.out.println("found: " + org.getName());
                    return new OrganisationRootFolder(applicationManager, org);
                }
            }
            // otherwise, look for a website with a name that matches the subdomain
            Website website = Website.findByName(subdomain, session);
            if (website != null) {
                System.out.println("found website: " + website.getName());
                return new WebsiteRootFolder(applicationManager, website);
            }
        }

        // Didnt find anything matching primary domain, so look for an exact match on website
        Website website = Website.findByDomainName(host, session);
        if (website != null) {
            return new WebsiteRootFolder(applicationManager, website);
        }

        // Still nothing found, so drop to root org admin console
        Organisation org = OrganisationDao.getRootOrg(SessionManager.session());
        if (org == null) {
            throw new RuntimeException("No root organisation");
        }
        System.out.println("fall through to rootorg: " + org.getOrgId());
        return new OrganisationRootFolder(applicationManager, org);
    }