Search code examples
umbracoumbraco7

Using optional parameters in Umbraco 7 Urls


Am new to using Umbraco. I need to create Urls with an an optional parameter on the end e.g.

mysite.com/people/john
mysite.com/people/jane
etc

however by default Umbraco appears to require a separate page for each person. Is there a built method in Umbraco that will allow me to define the last part of the Url as an optional parameter or do I have to write a custom route for it?

Thanks


Solution

  • You have a couple of options here.

    1. Use IIS URL Rewriting to rewrite your URLs under the hood and rewrite /people/john to /people/?person=john say. Then you can pick up the person from the query string on the page.

    2. Write a custom URL Finder that looks for the URLs and does some stuff under the hood, like get the people page, and then set a context item with the person name in for you to use in your views etc.

    3. You could write a custom route for it. Custom routing in Umbraco is slightly different to in normal MVC. Here is a blog post detailing how you can do it: http://shazwazza.com/post/custom-mvc-routes-within-the-umbraco-pipeline/