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/
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.
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)?
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:
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!
@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:
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 :)
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?
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:
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.
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?
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.
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?
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)?
I haven't benchmarked the whole thing, but I think the cost of having a few domains is non-significant.
Glad that it works!
I'd love to get these domain mappings into a config file...
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 finallywww.sitename.org.uk
. In umbraco the first site has the hostname on the homepage node aswww.sitename.org.uk
.I've added the following to my
ApplicationStarting
event handler:If I run the solution locally and browse to
localhost:64970
I am redirected towww.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?
@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:
So in ApplicationStarting we register the three environments like this:
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 useswww.mydomain.com
- it just works :)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?
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: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!
Thanks Dan, I'll give that a go today.
is working on a reply...