Click here to Skip to main content
13,094,411 members (72,660 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads


129 bookmarked
Posted 12 Feb 2009

URL Rewriting using ASP.NET for SEO

, 25 Feb 2009
An article describing how to implement URL rewriting in ASP.NET using three different methods
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head id="Head1" runat="server">
    <style type="text/css">
        body{ font-family: Tahoma; font-size: 12px;}
    <form id="form1" runat="server">
        Url Rewriting Sample Website</h1>
        <h2>Written by Steve J. Riggall</h2><br />
        <br />
        This sample web site uses an HTTP handler to rewrite requests for *.html 
        <br />
        <br />
        For this to work in IIS6 you need to add a resource mapping to the website 
        properties by clicking the "Configuration" button on the "Home Directory" tab 
        (or "Virtual Directory" tab for an application virtual folder), and adding a 
        mapping for the *.html to the ASP.NET ISAPI extension.&nbsp; This is usually 
        located at <strong>C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll</strong> but you 
        can always find and copy the properties for the *.aspx mapping if you are 
        unsure. You also need to ensure you un-check the option to make sure the 
        requested resource exists on the server.<br />
        <br />
        The rewriting should just work when hosted under IIS7 as the handler mappings 
        are already present in the web.config file.<br />
        <br />
        <br />
        <br />
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/FriendlyPage.ashx">Visit &quot;FriendlyPage.ashx&quot;</asp:HyperLink> (This is a rewritten page.  It should work with or without IIS mappings as *.ashx are already mapped to ASP.NET ASAPI)
        <br />
        <br />
        <asp:HyperLink ID="HyperLink2" runat="server" 
            NavigateUrl="~/UnfriendlyPage.aspx">Visit &quot;UnfriendlyPage.aspx&quot;</asp:HyperLink> (This is the aspx page that the above link is mapped to.)
        <br />
        <br />
        <asp:HyperLink ID="HyperLink3" runat="server" 
            NavigateUrl="~/ActualPage.html">Visit &quot;ActualPage.html&quot;</asp:HyperLink> (This is an actual static html page.  It should be served correctly.)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Steve Riggall
Technical Lead Hidalgo Limited
United Kingdom United Kingdom
Steve is an MCP and senior software developer for Hidalgo Limited (

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 25 Feb 2009
Article Copyright 2009 by Steve Riggall
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid