Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version

URL Rewriting using ASP.NET for SEO

, 25 Feb 2009 CPOL
An article describing how to implement URL rewriting in ASP.NET using three different methods
Url-Rewriting-in-ASPNET.zip
UrlRewriterSample
App_Code
App_Data
UrlRewriterSampleWithoutIIS.zip
UrlRewriterSampleWithoutIIS
App_Code
App_Data
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        body{ font-family: Tahoma; font-size: 12px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
        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 
        resources.
        <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.html">Visit &quot;FriendlyPage.html&quot;</asp:HyperLink> (This is a rewritten page.  If the link doesnt work you have not set up IIS correctly)
        <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.)
    
    </div>
    </form>
</body>
</html>

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.

License

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

Share

About the Author

Steve Riggall
Technical Lead Hidalgo Limited
United Kingdom United Kingdom
Steve is an MCP and senior software developer for Hidalgo Limited (http://www.hidalgo.co.uk).

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