05 January, 2012

Enabling correct URL's for umbraco when using hostnames on level 3+

I have in my company been running a single Umbraco installation with multiple websites for about 2½ year, each site has it's own domain, but share similar macros, and many times also functionality. But lately we have been running into issues with customers who would like to have multilingual sites under separate domain names.

Simple, right... just create a "folder" node, but each site inside and that should be it....!! But ups there is an old bug (missing feature) in Umbraco that will render out wrong URL's on both the backend and the frontend when using the Node.NiceUrl or umbraco.library.NiceUrl(NodeID) methods. The bug is that the Umbraco NiceUrl method only will filter out the nodes on level one (internally in the code called level 2, because actually the root is level 1).

Example, if your node structure looks like this:
+Node1 (hostname: exampleA.com)
++Node2.2 (hostname: exampleB.com)

Umbraco will construct the NiceUrl of:
Node1.1 as "/Node1.1.aspx" (correct url)
Node2.2 as "/" (correct url)
Node2.3 as "/Node2.2/Node2.3.aspx" (wrong url) should be "/Node2.3.aspx"

So to fix this/add this feature I have modified the Umbraco version of the umbraco.presentation.library.cs
The patch is uploaded here: umbraco.codeplex.com/Download/...323577 (moved to: issues.umbraco.org/../U4-515)
The Umbraco Work Item is here: http://umbraco.codeplex.com/workitem/30662 (moved to: issues.umbraco.org/../U4-515)