Best URL rewriting technologies [Answered]RSS

4 replies

Last post Apr 03, 2009 08:10 PM by ruslany

  • Best URL rewriting technologies

    Mar 28, 2009 11:39 AM|markwill|LINK

    Full disclosure - I am not a professional programmer so the learning curve for any one technology can be a little steep (since I have a day job!). But I am reasonably comfortable with ASP.Net (have used it since 1.0), C# and SQL Server. My environment is WS 2008 (dev and production environment), VS 2008 and IIS 7.0. So, with those qualfiers in place...

    I have a web site that has a number of URL rewriting needs. These include:

    • <div mce_keep="true">Mapping SEO/user friendly URL formats (/vendors/california/) to internal URLs (/vendors/state.aspx?ID=CA)</div>
    • <div mce_keep="true">Mapping old / moved URLs to their new locations, via a database lookup. For example, if I decide to restructure my site to a new organisation, I need to make sure that links to old/discontinued URLs are redirected (via 301 presumably) to their new location</div>
    • <div mce_keep="true">Generic mapping of various formats to their more URL friend versions (for example, mapping to and so on). I do have a licensed copy of ISAPI Rewrite if that helps.</div>

    I am about to go through a significant redesign of my site and have an opportunity to really clean things up. This includes embracing/learning the "right" technologies for each of the needs above. I have read various (rather technically deep) about the IIS "pipeline" and where it's possible to interject custom code (HTTP handlers, etc). But it is not leaping out at me what is feasible for a simple managed code developer such as me!

    I'd be very appreciative of any suggestions as to the most appropriate, current technologies or components to address these needs.

    Thanks in advance.



    URL rewriting

  • Re: Best URL rewriting technologies

    Mar 30, 2009 03:02 PM|markwill|LINK

    Shoot - I accidentally posted to the IIS 5/6 forums, when I meant to post to the IIS 7.0 Extensibility forum. Anyone know if it can be moved, without me posting there too? I was hoping this might be caught when it was approved.

    By the way, what's the criteria for when a post needs to be approved by the forum admins - I posted to a different forum here and that was posted immediately (no apparent "approval" took place) but this one took a couple ofo days to get approved.



  • Re: Best URL rewriting technologies

    Mar 31, 2009 01:20 PM|ruslany|LINK

    Microsoft URL Rewrite Module for IIS 7 can be used to perfrorm most of the tasks you described here. The only thing it cannot do is database lookup of old/moved URLs, but I think it would be good for you to evaluate if database is really necessary for that. URL rewrite module has a concept of rewrite maps where you can define mappings between old and new URL's. The rewrite maps are stored in web.config files. Here are the articles that may help you:

    Mapping SEO/user friendly URL formats:

    Mapping old/moved URLs to their new locations:

    Generic mapping of various formats to their more URL friendly versions:

    If you are completely redesigning your web site, you may also want to look into using ASP.NET MVC and its routing functionality, which allows web applications to have clean URL's without involing any of the URL rewriting techniques. This article explains when to use ASP.NET Routing and IIS URL rewriter:

  • Re: Best URL rewriting technologies

    Apr 01, 2009 01:10 AM|markwill|LINK

    Thank you. This is very helpful. I do need database lookup for a good numer of scenarios but do believe the URL Rewrite Model could help as well (in fact, I already use it in production).

    ASP MVC looks like a pretty significant learning curve for a mere "non-professional" programmer such as myself. Here's what I think will work...

    • <div mce_keep="true">The URL Rewrite Model for mapping of static URLs</div>
    • <div mce_keep="true">Trapping 404 errors through Application.Error() to support my database lookup needs, using Server.Transfer() for 301 redirection when I successfully locate a record in my database</div>
    • <div mce_keep="true">"Fall through" the Application.Error method when I truly have a bad page request, passing into my custom 404 page, as configured for IIS</div>

    Does this seem like a reasonable approach?

    By the way, is there any documentation on performance of the URL Rewrite module (at which point does it start to choke as the number of rules grows)? I know - a bit of a broad question but are we talking 10's of rules, 100's, 1000's, etc?



  • Re: Best URL rewriting technologies

    Apr 03, 2009 08:10 PM|ruslany|LINK

    I got this advice from ASP.NET team:

    Using the Url Rewrite module, you could deterministically rewrite Urls like:


    to a Url like:


    Then if the products.aspx page doesn’t find anything, the code in the products.aspx page can just do something like:

            if (//didn’t find any data)

    Where errorpage.aspx can be any regular ASP.NET web page, but with the addition of the following in the page load event:

    Response.StatusCode = 404;

    With regards to the number of rules the rewrite module can handle: the module will not choke on 100 or 1000's of rules, but it will slow down your application. This is because of regex pattern matching, which is an expensive operation. If you have so many rules, you should probably consider using rewrite maps instead (