While I'm not using the content finder (I'm using URL rewriting), I am using a custom URL provider so I don't have to worry about prefixing all of my URL's with "/en-us". Here's the implementation if you are curious:
// Namespaces.
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Web;
using Umbraco.Web.Routing;
/// <summary>
/// Builds international URL's.
/// </summary>
public class InternationalUrlProvider : DefaultUrlProvider
{
#region Constants
private const string ErrorBuildingUrl = "Error while attempting to build international URL.";
#endregion
#region Constructors
/// <summary>
/// Default constructor.
/// </summary>
public InternationalUrlProvider() : base(UmbracoConfig.For.UmbracoSettings().RequestHandler)
{
}
#endregion
#region Public Methods
/// <summary>
/// Gets the URL's for other domains.
/// </summary>
public override IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
var urls = base.GetOtherUrls(umbracoContext, id, current);
return urls == null
? null
: urls.Select(x => InternationalizeUrl(x, umbracoContext)).ToList();
}
/// <summary>
/// Gets the main URL.
/// </summary>
public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
var url = base.GetUrl(umbracoContext, id, current, mode);
return InternationalizeUrl(url, umbracoContext);
}
#endregion
#region Private Methods
/// <summary>
/// Internationalizes a URL.
/// </summary>
private string InternationalizeUrl(string url, UmbracoContext umbracoContext)
{
// Log errors.
try
{
var validRequest = umbracoContext != null && umbracoContext.HttpContext != null
&& umbracoContext.HttpContext.Request != null;
var request = validRequest ? umbracoContext.HttpContext.Request : null;
var lang = validRequest ? request.QueryString["lang"] : "en-us";
if (string.IsNullOrWhiteSpace(lang))
{
lang = "en-us";
}
var baseUri = default(Uri);
var validBase = false;
try
{
baseUri = new Uri(url);
validBase = true;
}
catch
{
baseUri = new Uri("http://www.site.com/");
}
var builder = new UriBuilder(new Uri(baseUri, url));
var path = builder.Path.TrimStart("/".ToCharArray());
var langPart = lang + (string.IsNullOrWhiteSpace(path) ? null : "/");
builder.Path = "/" + langPart + path;
url = validBase ? builder.Uri.AbsoluteUri : builder.Uri.PathAndQuery;
}
catch (Exception ex)
{
LogHelper.Error<InternationalUrlProvider>(ErrorBuildingUrl, ex);
}
// Return URL.
return url;
}
#endregion
}
And here's how I register that URL provider:
// Namespaces.
using Routing;
using Umbraco.Core;
using Umbraco.Web.Routing;
/// <summary>
/// Handles application startup.
/// </summary>
public class MyAppStart : ApplicationEventHandler
{
#region Methods
/// <summary>
/// Application starting.
/// </summary>
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication,
ApplicationContext applicationContext)
{
// URL provider for international URL's.
UrlProviderResolver.Current.RemoveType<DefaultUrlProvider>();
UrlProviderResolver.Current.InsertType<InternationalUrlProvider>();
// Boilerplate.
base.ApplicationStarting(umbracoApplication, applicationContext);
}
#endregion
}
As I mentioned, I'm not yet using a content finder, so this is what my URL rewrites look like:
URL rewriting
Hello,
I see this package uses the UrlRewriting.config file. You can also do this with a UrlProvider and ContentFinder.
Some more info: http://24days.in/umbraco/2014/urlprovider-and-contentfinder/
I've created an example which uses 1-1 multilingual. So a single node can have different URLs per language.
You can find more info here: https://our.umbraco.org/projects/developer-tools/1-1-multilingual-example/
Jeroen
Thanks! I'll have a look...
While I'm not using the content finder (I'm using URL rewriting), I am using a custom URL provider so I don't have to worry about prefixing all of my URL's with "/en-us". Here's the implementation if you are curious:
And here's how I register that URL provider:
As I mentioned, I'm not yet using a content finder, so this is what my URL rewrites look like:
That's a pretty good idea!
When I was using Umbraco myself, I was doing it this way: http://dimitros.be/en/blog/betterseowithpolyglot/
is working on a reply...