According to Wikipedia the definition of URL Redirection is:
URL redirection, also called URL forwarding, domain redirection and domain forwarding, is a technique on the World Wide Web for making a web page available under many URLs.
The customer I am currently working for already uses URL redirection, but their current URL redirection mechanism is not really flexible for them. Everytime they launch a campaign (in which they use a shortcut URL version) they have to file in a call to the maintenance department of their firm. They will then add a wildcard mapping in IIS, which uses an ISAPI handler, that will redirect the requested URL to the destination URL. The whole process should be able to work without the need of the maintenance department.
So the question is, how will URL redirection work, without using ISAPI handler, wildcard mapping and IIS configuration and that in combination with Sitecore?
I started by defining a new ShortCutUrl template:

Then added the Master:
The Sitecore items are created like this, where the data fields have a mapping relation. The shortcut extensionless URL’s will eventually be mapped to the related content item:
ShortcutURL: http://www.domainname.com/campaign
RedirectURL: http://www.domainname.com/Category/news/campaign.aspx
How do we all glue it together when a request is made to an extensionless URL?
When you request extensionless URL, you get a HTTP 404 page. IIS will receive the request and it serves the page configured for HTTP 404. This is by default a .htm page. But for us to be able to redirect the URL alle we have to redirect it to an .aspx file in our web folder. So configure IIS to redirect to some .aspx extension when a missing extensionless url is hit. In this case I map it to a 404.aspx file.

When the redirect is made, Sitecore will begin processing the entire processor tree in a sequential way. So hook in a processor between the ItemResolver and the LayoutResolver as recommended on the Sitecore Developer Network (SDN5).
Just register the processor, that will server as a URL redirector, as shown below in the web.config file:
< httpRequestBegin >
...
< processor type = "Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel" />
< processor type = "Sitecore.Custom.UrlRedirectionResolver, Sitecore.Custom" />
< processor type = "Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel" />
...
</ httpRequestBegin >
< httpRequestEnd >
This is the class that will make it all happen!
using System;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Pipelines.HttpRequest;
using Sitecore.Web;
namespace Sitecore.Custom
{
public class UrlRedirectionResolver
{
public void Process(HttpRequestArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (Context.Item == null)
{
string[] urlInfo404 = args.QueryString.Split(';');
if (urlInfo404.Length > 1)
{
string originalUrl = urlInfo404[1];
string[] urlParts = originalUrl.Split('?');
string queryString = string.Empty;
string requestedFile = string.Empty;
if (urlParts.Length > 1)
{
requestedFile = urlParts[0];
queryString = urlParts[1];
}
else
{
requestedFile = urlParts[0];
}
Uri requestUri = new Uri(requestedFile);
Item foundItem =
Settings.Items.ShortcutUrlsFolder.Axes.SelectSingleItem(
String.Format("//*[CompareCaseInsensitive(@ShortcutUrl,'{0}')]",
requestUri.LocalPath.StartsWith("/")
? requestUri.LocalPath.Remove(0, 1)
: requestUri.LocalPath));
if (foundItem != null)
{
InternalLinkField link = foundItem.Fields["RedirectUrl"];
string redirect = requestUri.AbsoluteUri.Replace(requestUri.AbsolutePath, "") +
link.TargetItem.Paths.GetFriendlyUrl(true).Replace(
Factory.GetSiteInfo("website").RootPath, "");
Log.Info(string.Format("Orginal URL = {0}", requestUri.ToString()), this);
Log.Info(string.Format("Redirect to = {0}", redirect), this);
WebUtil.Redirect(queryString == string.Empty ? redirect : redirect + "?" + queryString);
}
else
{
WebUtil.Redirect(queryString == string.Empty
? requestedFile + ".aspx"
: requestedFile + ".aspx?" + queryString);
}
}
}
}
}
}
The inspiration for this article:
I found a great article on codeproject by Omar Al Zabir:
http://www.codeproject.com/KB/aspnet/extensionless.aspx?fid=957601&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2448667
You can find more information on the SDN5 developer network, as well in the blog from Lars Floe Nielsen about how to handle 404 errors:.
http://sdn5.sitecore.net/Scrapbook/Handle%20404%20errors.aspx
http://sdn5.sitecore.net/Scrapbook/Custom%20HttpHandler%20problem.aspx
http://larsnielsen.blogspirit.com/archive/2007/10/17/modifying-the-httprequest-pipeline-custom-404-handler.html
Hope this is usefull!
Gr.
Robbert