Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Dec 12, 2013 @ 14:06
    Dan Diplo
    2

    Multiple hostnames for one root node - how does it work?

    I've got a single instance of Umbraco 6.1.6 that incorporates three different sites ie. there are three root Home nodes and each of those nodes has a host name with a different domain. Something like:

    Content
    -- Site One (siteone.local)
    -- Site Two (sitetwo.local)
    -- Site Three (sitethree.local)

    If I'm editing a page in Umbraco on siteone.com domain (ie. siteone.com/umbraco/) and create a link to a page in Site Two then Umbraco NiceUrl generates an absolute URL eg. /sitetwo.com/news/article-one/  This is fine and works as expected.

    However, I'm in a situation where I have to have two hostnames for each site - so that during development the site can run on my local machine and also a staging server where content is being added (not ideal, but it's necessary).

    So now we have:

    Content
    -- Site One (siteone.local , siteone.staging)
    -- Site Two (sitetwo.local, sitetwo.staging)
    -- Site Three (sitethree.local, sitetwo.staging)

    I find that if I run the site on siteone.staging OR siteone.local that NiceUrl always generates Urls to the other site using the last added domain - in this case siteone.staging.

    So I might be browsing on siteone.local, publish a page, but all links from Site One to Site Two will link to /sitetwo.staging/  

    This isn't a massive problem, but seems to contradict what Stephan told me in https://twitter.com/zpqrtbnk/status/411113570513203200

    Not a big deal, just curious! Hope that makes sense?

  • Stephen 767 posts 2273 karma points c-trib
    Dec 12, 2013 @ 18:10
    Stephen
    102

    Not sure it contradicts what I said.

    If you're browsing siteone.local and get the url for a page under SiteOne then you'll get a relative url. Because it works. If you explicitely request an absolute url, you'll get an absolute url and that url's domain will be siteone.local. Conversely, if you're browsing siteone.staging, the domain will be siteone.staging.

    If you're browsing on siteone.anything and get the url for a page under SiteTwo then you'll get an absolute url because it is another site. That url's domain has to be either sitetwo.local or sitetwo.staging. How to we figure out which to pick? By default it might be that we pick the last one (staging) -- that's the behavior that you are experiencing.

    So we have the ISiteHelper detailed in http://www.zpqrtbnk.net/TheUmbraco6RequestPipeline.pdf starting at p37. You want to bind the two "local" sites together, and the two "staging" sites together.

    SiteDomainHelper.AddSite("local", "siteone.local", "sitetwo.local");
    SiteDomainHelper.AddSite("staging", "siteone.staging", "sitetwo.staging");

    Now when you browse siteone.local and get a url for a page under SiteTwo, we'll use sitetwo.local because it's bound to siteone.local.

    Making sense?

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Dec 12, 2013 @ 18:32
    Dan Diplo
    0

    Wow, Stephan, thanks for your help. I tried what you said... and it works! Big thanks.

    I'm really impressed how so much stuff in the new pipelines are configurable / overrideable. As you say, this is probably a corner case, but the fact that the defaults can be overriden in such a simple way is a great testament to your engineering (and the rest of the team). #h5yr

    Just one more question - when the site goes live it will be on yet another domain - would it hurt performance to leave the enteries for "local" and "staging" in, or would it be best to remove them (and the extra host headers)? 

  • Stephen 767 posts 2273 karma points c-trib
    Dec 12, 2013 @ 19:31
    Stephen
    0

    I haven't benchmarked the whole thing, but I think the cost of having a few domains is non-significant.

    Glad that it works!

  • Gary Bond 13 posts 36 karma points
    Jan 31, 2014 @ 12:46
    Gary Bond
    0

    I'd love to get these domain mappings into a config file...

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jan 27, 2017 @ 14:36
    Simon Dingley
    1

    I've read the documentation and I've had a go at implementing this in order to test it but for some reason I'm struggling to understand how this should work, or why, in my case, it is not working.

    I have a multi-site install which contains around 13 sites each with a primary hostname on the homepage node. The sites move from local to staging and then live. Each environment requires a different hostname to access the sites. e.g. sitename.org.uk.local, staging.sitename.org.uk and finally www.sitename.org.uk. In umbraco the first site has the hostname on the homepage node as www.sitename.org.uk.

    I've added the following to my ApplicationStarting event handler:

    SiteDomainHelper.AddSite("sitename-uk", "www.sitename.org.uk", "staging.sitename.org.uk", "sitename.org.uk.local", "localhost:64970");
    SiteDomainHelper.BindSites("sitename-uk");
    

    If I run the solution locally and browse to localhost:64970 I am redirected to www.sitename.org.uk.

    What I want to avoid is going back to adding multiple hostnames in Umbraco because I have in the past encountered problems with links being generated with the wrong hostnames!

    Am I missing something here?

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jan 30, 2017 @ 15:09
    Dan Diplo
    3

    @Simon - the way I've also done it from multi-domain sites is this way. So in ApplicationStarting you need to register the sites for each environment. So, for instance, we have 3 environments for a site:

    • local - runs on localhost on developers machine
    • staging - runs on a staging server on a generic domain
    • live - the live domain(s)

    So in ApplicationStarting we register the three environments like this:

    SiteDomainHelper.AddSite("local", "localhost:12345");
    SiteDomainHelper.AddSite("staging", "staging.mydomain.com");
    SiteDomainHelper.AddSite("live", "www.mydomain.com");
    

    These then should map to the host headers (Cultures and Hostnames) you set in Umbraco. So for the home page of each site you'd add all those domains for every culture. When Umbraco runs it then automatically resolves the URL based on the domain it's running on. So when you run it locally it uses localhost:12345 but when live it uses www.mydomain.com - it just works :)

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jan 30, 2017 @ 16:42
    Simon Dingley
    0

    Ok, I think I've got it. So I still need the hostnames on the nodes. What I essentially need to do is to replicate those 3 lines for each site in the install?

    SiteDomainHelper.AddSite("local", "localhost:12345");
    SiteDomainHelper.AddSite("staging", "staging.sitename.com");
    SiteDomainHelper.AddSite("live", "www.sitename.com");
    
    SiteDomainHelper.AddSite("local-fr", "sitename.local.fr:12345");
    SiteDomainHelper.AddSite("staging-fr", "staging.sitename.fr");
    SiteDomainHelper.AddSite("live-fr", "www.sitename.fr");
    
    SiteDomainHelper.AddSite("local-it", "sitename.local.it:12345");
    SiteDomainHelper.AddSite("staging-it", "staging.sitename.it");
    SiteDomainHelper.AddSite("live-it", "www.sitename.it");
    
    ...
    
  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jan 30, 2017 @ 19:04
    Dan Diplo
    1

    Yep, you still need to add the hostnames to the nodes - Umbraco then chooses the correct one based on what the current domain is (presumably based off the request URL host).

    I think you shorten your code as you can add multiple domains per AddSite method. Something like this:

    SiteDomainHelper.AddSite("local", "localhost:12345", ""sitename.local.fr:12345", .... etc);
    
    SiteDomainHelper.AddSite("staging", "staging.sitename.com", ""staging.sitename.fr", ... etc);
    
    SiteDomainHelper.AddSite("live", "www.sitename.com", ""www.sitename.fr", etc...);
    
  • Simon Dingley 1470 posts 3427 karma points c-trib
    Sep 06, 2017 @ 09:47
    Simon Dingley
    0

    Late replying to this but I have just used it on another less complex site and this works great for binding hostnames together for browsing in different environments e.g. staging links to staging domains and live links to live domains.

    Thanks!

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jan 31, 2017 @ 09:39
    Simon Dingley
    0

    Thanks Dan, I'll give that a go today.

Please Sign in or register to post replies

Write your reply to:

Draft