Go to content

Go to employees

Go to search

Lower case URLs in EPiServer

EPiServer default generates all url's width the casing written by the author. This is not necessarily considered good practice according to SEO-standards. According to SEO best-practice, an url should be all lower case.

Lars Timenes
 

This issue can be fixed with a few simple steps.
To get all your site urls to display in lower case do the following:

1. Add the following in your Global.asax.cs:

void UrlSegment_CreatedUrlSegment(object sender, EPiServer.Web.UrlSegmentEventArgs e)
        {
            e.PageData.URLSegment = e.PageData.URLSegment.ToLower();
        }

2. Add the following line in Application_Start

EPiServer.Web.UrlSegment.CreatedUrlSegment += new EventHandler<EPiServer.Web.UrlSegmentEventArgs>(UrlSegment_CreatedUrlSegment);

This pretty much fixes the issue, but to take care of all the URLs already created with CamelCase:

3. run the following sql on the database in question:

update tblPageLanguage set URLSegment = lower(URLSegment)

4 update previous versions (not really necessary, but if you want...):

update tblWorkPage set URLSegment = lower(URLSegment)

 

You now will get all URLs in lowercase. For the entire site.

PS! The observant visitor may notice that is not implemented on this site, - yet :-)

Tags:


Comments:

  1. Isn't the possible to do something like this in a PagePublishing event as well? Couldn't you lower-case the UrlSegment property prior to save?
  2. Correct. Basically that is what is done in step 2.
  3. Another way could be to make your own FriendlyUrlRewriter. Guess this could be done with only some few line of code.
  4. Why isn't the property "Page name in Web address" under the tab Advanced Information updated after I executed the sql-query in step 3? If the editor now edits that property and hit "save and publish" the url will be back in upper case.
Post a comment