Url Mapping made easy


It is always the trouble. You create a new website or move to another provider, and you get a ton of "Page not found" errors in your statistics.
Very rarely do links from one system map up directly to the links in the new system and that causes a lot of Page not found errors to occur.

The answer though is getting easier and easier.

In the realm of URL Mapping, things can get rather complex. There are tons of requirements, from disguising complex query strings containing guids and ugliness, to the more security conscious disguises. Right at the bottom, where url mapping only begins, is there a simple requirement. Map old links to new links.

On this simple level, whether it contains a querysting value or not, you can use the ASP.NET 2.0 urlMappings node in Web.Config.
This node is elegant and simple. Here is an example from this website where we moved to our new Content Management System, we added these to help guide the old search engine links to a more helpful alternative.


.... config snippet
<system.web>

    <urlMappings enabled="true">

      <add mappedUrl="~/General/Portfolio.aspx"  url="~/portfolio.aspx"  />
      <add mappedUrl="~/General/Contact_Us.aspx"  url="~/about.aspx"  />
      
    </urlMappings>

... end snippet 

thats straight forward, but what about querystrings?

Well it is just as simple. Add the querystring to the path as below. You could potentially create a range or even redirect products as in product.aspx?id=4 to a more friendly url which is generated by your "engine".

    <add mappedUrl="~/General/Portfolio.aspx" url="~/portfolio.aspx?myparam=Something" />
<add mappedUrl="~/General/Portfolio.aspx" url="~/portfolio.aspx?id=4" /> 

References

MSDN Documentation