Creating custom 404 and landing pages (easy to remember URLs that are redirected) in SharePoint

This post is about how to create custom landing pages (www.mysite.com/products or www.mysite.com/newsletter) that directs the visitor through and easy to remember URL to any pageĀ  in your deep site hierarchy. It also contains the approach how to create custom 404 "Page not found" pages.

In this, I'll only explain you the concepts, since I don't really know if I get to code this within a reasonable timeframe. Next week, I'll start at Microsoft, so I'm not sure to have plenty of time for trying things out in the next weeks...

OK, what are we talking about: SharePoint URLs get constructed today a lot better than before. However, it is still not easily possible to create so called "landing pages". These are mostly just entry points that let a visitor easily find its content. Marketing campaigns can print easy to remember URLs on their advertisements etc. Need some examples? OK, here we go:

www.mycompany.com/winthis -- leads to --> www.mycompany.com/marketing/campaigns/summer07/signup.aspx
www.mycompany.com/subscribe -- leads to --> www.mycompany.com/salesandmarketing/ebusiness/newsletters/english/signup.aspx

How should we do this? If you enter such an URL in MOSS you'll get a 404 error. Of course, because this pages do not exists. You couldn't work with Redirect Pages either because they would be located in the "Pages/" section of any site.

Here is now my concept to implement this:

  • Customize the 404 landing page (I follow Jingmei's post): Create your "custom404.html" page. It must be a HTML page that redirects the requests, cannot be an ASPX page!

  • Create a custom "customRedirect.aspx" in the layouts section and implement code:

    • Lookup a special list in SharePoint "Landing Pages" using the "oldUrl" provided through the QueryString. The list contains a list of Landing Urls ("/newsletter") and the real URL ("www.mycompany.com/salesandmarketing/ebusiness/newsletters/english/signup.aspx") if you find a match, redirect the request to this page (use .NET Reflector how Microsoft does this). If you find no landing page redirect, I would redirect to a hidden publishing page on the root of your site that displays a fully branded 404-message.

    • Strong name the dll, create a feature and solution for deployment etc. For testing, it is enough to put the ASPX in the _layouts folder and the DLL in GAC.

  • Some thoughts

    • After reflecting a bit, I think it is only necessary to create one "Landing Pages Redirects" library at the root of your site. URLs typically should be as short and "human readable" as possible.

    • With this approach, you have a very robust 404-handling implemented. Do you need additional logic? Just implement it in the already created ASPX-logic.

If I get to it, I'll implement this scenario and create an easy to deploy SharePoint solution out of it. I think this could be interesting to add as a feature to any internet site.

Cheers!!
SOURAV
ME_Mag_thumb1