Home | Contact Us

CSharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript

ASP.NET UrlMappings Example: Redirects

This ASP.NET article shows how to use the UrlMappings element in Web.config.

UrlMappings. The urlMappings element redirects URLs to new locations.

This element is part of an ASP.NET config file. It redirects Googlebot and users alike to the new locations. It is easily added to Web.config to perform this complex task.

Example. We can use urlMappings, a special tag you can put in your Web.sitemap. Here is a table of some "old style" URLs that I want to map to new URLs. You can see the new URLs had SEO improvements with more keywords.

Examples for: url


Examples for: mappedUrl


Example 2. You can add urlMappings by adding markup to Web.config. The "~" symbol, called a tilde, is a reference to the root of the virtual application directory. That is the root directory of your website. This example shows the urlMappings tag.

Web.config examples: XML

<urlMappings enabled="true">
    <add url="~/Content/Page22.aspx"
    <add url="~/Content/Page9.aspx"

Open Web.config. This file is part of your website project in the Solution Explorer. You will need to double-click on it. Next, find the system.web element. Locate the <system.web> element and its closing tag.

Then: Put your <urlMappings> block into a section in the middle of that section.


Summary. We used urlMappings as a quick fix for redirecting requests on an ASP.NET server. There are other methods that may be more powerful. Use the RewritePath method in ASP.NET and Global.asax for a more flexible approach.