I’m looking to run two sites off one Sitecore install.
The first site will only be in UK English therefore I won’t include the language in the file path. languageEmbedding=never
The second site will be in multiple languages and I need to include the language in the file path. languageEmbedding=always
Is there a way I can define multiple link managers and configure the sites to use a specific link manager?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I’ve found the best way was to create a custom link manager that supports both scenarios. Then have a supporting config setting which defines whether the language is embedded.
public class LanguageLinkProvider : LinkProvider
{
public override string GetItemUrl(Item item, UrlOptions urlOptions)
{
urlOptions.SiteResolving = Configuration.Settings.Rendering.SiteResolving;
string sites = ConfigurationManager.AppSettings["EmbedLanguageInUrl"];
var splitSites = new List<string>();
if (!string.IsNullOrEmpty(sites))
splitSites = sites.Split(';').ToList();
if (splitSites.Contains(urlOptions.Site.Name))
urlOptions.LanguageEmbedding = LanguageEmbedding.Always;
else
urlOptions.LanguageEmbedding = LanguageEmbedding.Never;
return base.GetItemUrl(item, urlOptions);
}
}
Method 2
Nope, not by default.
But the LinkManager is overrideable. Probably you can change the behavior by selecting a different config per site and coding this into an overriden LinkManager.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0