EPiServer 301-handling

Got some room to breath today, so decided to split a simple 301-handling I did some weeks ago into it’s own project and “put it in the git”. Also made a nuget for it if anyone wants to try it out.

https://github.com/studsboll/EPiServer301Handler

I like nugets, if done correctly they make it very easy and clean to try code if you want to, and I’m trying to make it a natural part of when i package stuff for safekeeping.

So what does this thing do then?

Basic 301-handling for EPiServer 7.5+. Support for Domain-redirects. Based on XML-files to be as simple as possible doing nothing more and nothing less.

If domain-redirects exists, that request will be routed first with persistent relative path.

Routes will catch what EPiServer does not want and send it to controller for checking if it’s a 301, if it is, a permanent redirect will trigger to new place. If not, a 404-exception will be thrown falling back on website configured error-handling.

Installation
Drop bin-file in your bin-directory. All is IInitializable modules and will hook onto EPiServer.

Optional configuration, add to appsettings

These are also the default paths if no appsettings exist.
XML should look as follows

I trim surrounding /, as well as ignore lower/uppercase on compare. So not that important.

So what about errorhandling?

To accompany this module I usually redirect to a page in EPiServer. Webconfig as

Then I set a page in EPiServer to answer on /error address. The page someone tried to access can be found in TempData[“originalUrl”].

Leave a Reply

Your email address will not be published. Required fields are marked *