Main Content

Magnolia Community Forums: Get help with Magnolia: Different Domain mapping to single site root


  • shriduttkothari
    shriduttkothari
    Full name: shridutt kothari
    Posts: 4
    Last post: Dec 4, 2017 4:07:08 PM
    Registered on: Apr 10, 2017
    Different Domain mapping to single site root
    #1 by shriduttkothari on Nov 20, 2017 4:20:46 PM

    I have two domains which i want to map to single root of my website.

    And when user comes from domain1 and domain2, users should see different themes for same page.

    I have done all the multisite donfiguration and domain and mappings but when i am creating two site structures in pages app it workes but when i am trying to point two site configurations to single site structure in pages app it's not working.

    Any help with configuring two domains to single page url??

    Thanks,
    Shridutt

  • marvink2
    marvink2
    Full name: Marvin Kerkhoff
    Posts: 45
    Last post: Nov 22, 2017 9:14:20 AM
    Re: Different Domain mapping to single site root
    #2 by marvink2 on Nov 22, 2017 9:14:20 AM

    Hi,

    i would use one site definition for both domains. For the Themeing i would use a custom page model which i recommend for every project.

    public class DefaultPageModel extends RenderingModelImpl<RenderableDefinition> {

    private static Logger log = LoggerFactory.getLogger(DefaultPageModel.class);
    SiteManager siteManager;
    TemplatingFunctions templatingFunctions;
    SiteFunctions sitefn;

    @Inject
    public DefaultPageModel(Node content, RenderableDefinition definition, RenderingModel<?> parent,
    TemplatingFunctions templatingFunctions, SiteManager siteManager, SiteFunctions sitefn) {
    super(content, definition, parent);
    this.siteManager = siteManager;
    this.templatingFunctions = templatingFunctions;
    this.sitefn = sitefn;
    }

    @Override
    public String execute() {

    /*
    * Theme & Prototype Switch for domains
    *
    ConfiguredSite site = (ConfiguredSite) sitefn.site();
    ReferencingPrototypeTemplateSettings templateSettings = (ReferencingPrototypeTemplateSettings) site.getTemplates();
    ThemeReference themeReference = new ThemeReference();

    if (baseUrl().equals("domain1")) {
    themeReference.setName("domain1-theme-name");
    site.setTheme(themeReference);
    } else {
    themeReference.setName("domain1-theme-name");
    site.setTheme(themeReference);
    }

    return null;
    }

    public String baseUrl() {
    HttpServletRequest request = MgnlContext.getWebContext().getRequest();
    String protocol = "http";

    for (Domain domain : siteManager.getCurrentSite().getDomains()) {
    if (StringUtils.isNotBlank(domain.getProtocol())) {
    protocol = domain.getProtocol();
    break;
    }
    }

    StringBuffer baseUrl = new StringBuffer();
    baseUrl.append(protocol);
    baseUrl.append("://");
    baseUrl.append(request.getServerName());

    if (("http".equals(request.getScheme()) && request.getServerPort() != 80)
    || ("https".equals(request.getScheme()) && request.getServerPort() != 443)) {
    baseUrl.append(":");
    baseUrl.append(request.getServerPort());
    }

    return baseUrl.toString();
    }
    }

You don't have the permission to post on this thread

Sign in

To login on this forum, you can use your Magnolia Forge, Support or Partner account, or, below, your Google, Yahoo! or OpenID account. If you have trouble logging in, or any other sort of issue, please let us know in the Meta forum, on the user-list, or simply by email at forum-admin at magnolia-cms dot com.

* Required

... or sign in with:

  • icon http://{your-openid-url}
  • icon
  • icon https://me.yahoo.com/