.NET URL Routing: 301-Redirect for legacy URL’s

We are jumping from static .html site to new ASP.MVC version.
There are several legacy .html urls that we need to route to new controller’s methods.
Besides, we need to support new pure .html pages places in the project tree.

1. To provide legacy URL redirects (301-Permanent redirect) by URL Routing,
we mapped .html to Aspnet_isapi.dll in IIS settings of the web application.

2. Add routing for legacy URLs like:

routes.Add(new LegacyRoute(“{action}.html”, “Products”, new LegacyRouteHandler())
{
Constraints = new RouteValueDictionary { { “action”, “arena|gallery|construct” } }
});
routes.Add(new LegacyRoute(“advergames.html”, “Products”, new LegacyRouteHandler())
{
Defaults = new RouteValueDictionary { { “action”, “arena” } }
});
routes.Add(new LegacyRoute(“news2003.html”, “Company-Info-news”, new LegacyRouteHandler())
{
Defaults = new RouteValueDictionary { { “action”, “news” }, { “year”, “2003” } }
});
routes.Add(new LegacyRoute(“{game}.html”, “Games-Game”, new LegacyRouteHandler())
{
Defaults = new RouteValueDictionary { { “category”, “arcade” } }
,
Constraints = new RouteValueDictionary { { “game”, “alien-attack|alus-revenge|arcade-football” } }
});
routes.Add(new LegacyRoute(“{category}-games.html”, “Games-Category”, new LegacyRouteHandler())
{
Constraints = new RouteValueDictionary { { “category”, “arcade|card|casino” } }
});
routes.Add(new LegacyRoute(“games.html”, “Games-AllGames”, new LegacyRouteHandler()));
routes.Add(new LegacyRoute(“index.html”, “Root”, new LegacyRouteHandler()));

3. Process all other .html as regular pages

routes.Add(new Route(“*.html”, new StopRoutingHandler()));

4. Add Page-Not-Found routing

routes.MapRoute(
“404-PageNotFound”,
“{*url}”,
new { controller = “home”, action = “PageNotFound” }
);

5. For IIS-6 provide IHttpHandler for .html as we should process it in our ASPX application

<httphandlers>
<add path=”*.html” verb=”*” type=”System.Web.StaticFileHandler”></add>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: