The Publish Page URL Module for Sitecore Now Offers Root Override Support!

About a year ago I released the Published Page URL module, which shows authors the actual public URL for pages (something that Sitecore doesn't do). Well, now it supports media library items, allowing you to get the final URL for PDFs, Documents, etc. in multisite, multilingual environments.

This feature has operated under the context of navigable pages, referencing the public domain based on its path in the Content Tree. It also offers different domains based on language, like we have with some clients. Here's the new data section you see once this is installed, with an example of a Contact Us page.

This feature also supports media items since they have URLs your authors will likely want to share.

The New Root URL Option

Ok looking back, I made a post about a client who wanted hundreds of items in their site root that would be a redirect. This wouldn't be possible with a standard redirect item, so I shared code that would allow you to leverage a bucketed folder of redirects in a safe manner. Works great, but it doesn't get picked up by the Published Page URL Module. To resolve this, I added a list of templates which would assume it's in the site root:

<ItemTypesToTreatAsRootUrls hint="raw:LoadTreatAsRootUrlIds">

The above template is the very bucketed item type you would see in the linked post, so this will also show the published data section seen earlier. It does by simply checking to see if the item's type is defined under the above list:

var treatItemAsRootUrl = ItemTypesToTreatAsRootUrls.Any(x => x.Equals(editingItem.TemplateID));

It then continues through the regular process of building the URL to display, but after getting the item's path, it sees if the above value is True. If so, it strips down the path to just the navigable name and adds it right after the site's domain name:

if (treatItemAsRootUrl)
    if (path.StartsWith("/"))
      path = path.Substring(1);
    var pathParts = path.Split('/');
    if (pathParts.Length > 1)
      path = $"/{path.Split('/').First()}/{path.Split('/').Last()}";
      path = $"/{path.Split('/').Last()}";

So what we wind up with is the site's Url as defined in the config file, and the redirect item's name.

What's Next?

I realize the root redirect post could better serve the community as a module, which will get released soon!