URL Rewriting in EPiServer 6

Today I was working on a project that uses EPiServer version 6. As you probably know EPiServer 6 is still using webforms, not MVC. For SEO optimalisation we needed to rewrite incoming URL’s to make them uniform. For example all these URL’s should go to the same page

/en/Some-Interesting-Page
/Some-Interesting-Page
/en/some-interesting-page

For SEO it is important that there is only one valid URL. Other URL’s should throw a statuscode 301 and redirect to the correct url. For this I needed to do some URL rewriting in EPiServer.

Normally you would start catching an incoming request in the Global.asax.cs file in this method:

Unfortunality EPiServer overrules this method and therefor its never fired. Instead we need to make a event handler by extending EPiServer functionality:

Now we can catch the request in the application_BeginRequest method. What I now want to do is:

  1. Get the raw URL that makes the request
  2. This is a SEO friendly url. Convert it to an internal url so we can get the pagereference.
  3. Get the pagereference from this internal url.
  4. Convert this internal url back to a user friendly url.

Some other code snippets you might like

More information

Leave a Comment.