For a number of reasons it's widely recommended to use all lowercase URL's inside a web site. Unfortunately EPiServer out of the box uses the same casing as the entered PageName (unless you modify the URL manually).

In order to always get a lowercase URL here's some code we've been using for ages. Hook it up on the SavingPage and CreatingPage events and make your web site a little bit better.

using EPiServer.Web;
if (string.IsNullOrEmpty(page.URLSegment)) { page.URLSegment = UrlSegment.CreateUrlSegment(page); } if (!string.IsNullOrEmpty(page.URLSegment)) { page.URLSegment = page.URLSegment.ToLower(); } if (page.URLSegment.Contains("--")) { page.URLSegment = Regex.Replace(page.URLSegment, "--+", "-"); }

UPDATE: Check out Joel's blog post for a complete example compatible with EPiServer 7.

Added Wednesday 16 January 2013 18:20 — Tags for this page: Episerver


  1. Arild Henrichsen Wednesday 16 January 2013 20:12

    Good post. Lowercase URLs is definitely one of those simple SEO fixes that should come out of the box. We've been using the same technique, but another approach is to place your EventHandler in Application_Start (global.aspx.cs), it will then take effect for every event where CreateUrlSegment is invoked.
    Also contains some tips on how to fix existing URLs with mixed casing :-)

  2. Author Comment Wednesday 16 January 2013 21:06

    Nice! I didn't know of the CreatedUrlSegment event. You should add it to btw ;-)

  3. Tahir Thursday 17 January 2013 14:45

    Replacing "--" with "-" in CreatedUrlSegment will create conflicting urls. Imagine you have published a page with page name "Page--name" and with "Page-name" under a specific page. If you replace "--" in CreatedUrlSegment it will generate the same url for both pages.

  4. Author Comment Thursday 17 January 2013 14:57

    Thanks for commenting! The chances are fairly slim I would say. That replace mostly catches double dashes being generated from strings such as "& " in a PageName. I'd rather have a conflict once in a million than a ugly URL once in ten. But I also think EPi adds a number if the segments are identical, no?

  5. Tahir Thursday 17 January 2013 16:14

    Yes, EPiServer makes the URL unique but that occurs before CreatedUrlSegment is called (Thanks to Reflector:) ).

  6. Jeroen Thursday 17 January 2013 17:12

    You could ofcourse add a rewrite rule to the web.config like this:

    <rule name="Force lower case" stopProcessing="true">
    <match url=".[A-Z]." ignoreCase="false" />
    <add input="{REQUEST_URI}" pattern="^/EPiServer/" negate="true" />
    <add input="{URL}" pattern="^.*\.(axd|css|js|jpg|jpeg|png|gif)$" negate="true" ignoreCase="true" />
    <action type="Redirect" redirectType="Permanent" url="{ToLower:{URL}}" />

  7. Mon Thursday 7 November 2013 14:05

    Hi Joroen,

    Your suggestion is it works for me. but the toolbox for composer not display properly. Any idea about this please? Thanks.,

Add Your Comment