Sitecore ASP.NET - manage domain aliases
I have a site with Sitecore 6.3. This site includes some sub-sites (for example, www.a.com and www.b.com). I want to ask if it is possible to create separate aliases for these sites (eg www.a.com/alias and www.b.com/alias should be redirected to different pages). Now, if you create an alias for www.a.com, it will also be available at www.b.com. Any ideas how to manage this? Thnx.
source to share
It is possible. For this, I have already received a Sitecore support ticket. I also worked on this and their solution worked great for me. (haven't implemented it on a live website yet because we didn't have an agreement on the costs yet). This is some sample code you can look at:
class MultiSiteAliasResolver : AliasResolver
{
public new void Process(HttpRequestArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (!Settings.AliasesActive)
{
Tracer.Warning("Aliases are not active.");
}
else
{
Sitecore.Data.Database database = Sitecore.Context.Database;
if (database == null)
{
Tracer.Warning("There is no context database in AliasResover.");
}
Item aliasItem = getAliasItem(args);
if (aliasItem != null)
{
LinkField linkField = aliasItem.Fields["Linked item"];
if (linkField != null)
{
Item AliasLinkedTo = Sitecore.Context.Database.GetItem(linkField.TargetID);
if (AliasLinkedTo != null)
{
Sitecore.Context.Item = AliasLinkedTo;
}
}
else
{
base.Process(args);
}
}
}
}
/// <summary>
/// Gets the alias item.
/// </summary>
/// <param name="args">The args.</param>
/// <returns></returns>
private Item getAliasItem(HttpRequestArgs args)
{
string websitePath = Sitecore.Context.Site.RootPath.ToLower();
if (args.LocalPath.Length > 1)
{
Item aliasItem = Sitecore.Context.Database.GetItem(websitePath + "/settings/aliassen/" + args.LocalPath);
if (aliasItem != null)
{
return aliasItem;
}
}
return null;
}
}
This class can be inserted into web.config instead of AliasResolver. For example:
<processor type="CommandTemplates.Classes.MultiSiteAliasResolver, CommandTemplates" />
I hope this works for you, good luck!
update: In my example, I have a folder under each website node "/ settings / aliassen /" that I want users to set aliases. By the way, also note that if you change the AliasResolver like this, the window that the standard Sitecore Alias triggers will no longer have the required functionality. I didn't have time to put together a way to make this work, however you can always explain to content managers how to work with your new solution.
source to share