This little gem is a .NET dll, weighing in at 97kb that can be used to provide friendly urls for any asp.net web sites that you might be creating.

If you are familiar with Apache modrewrite then you know how powerful this can be for url rewriting and relatively easy to use. Being a well supported technique and well known, Apache modrewrite makes a great choice for url rewriting even from a .NET application.

Instead of this as your site url format:

http://www.bangdesign.com.au/ProjectCategory.aspx?Category=1&Project=94864415-85f0-4e73-9781-d4c0aa649be5

How about this:

http://www.bangdesign.com.au/projects/product/caroma/lucid

Not only is this easier for people to read and remember but it’s great for SEO.

Getting this to work is pretty straighforward and requires the following steps:



  1. Include the ManagedFusion.dll in your .NET project
  2. Add a few configuration settings to your web.config file (documented in the readme.txt)
  3. Create a rules file named ‘ManagedFusion.Rewriter.txt’ and start writing your rules.

All the following rules defined at http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html are supported.

  1. RewriteBase
  2. RewriteCond
  3. RewriteEngine
  4. RewriteRule
  5. RewriteLog
  6. RewriteLogLevel

But what about if my site contains a whole load of dynamic content?

Not a problem. The site I have created for Bang Design contains a catalog of products that is being updated by the guys at Bang Design all the time.

Each time they modify the catalog the ManagedFusion.Rewriter.txt file is updated with the new or modified entries.

The technique I use is to maintain a set of ‘base’ rules in a separate file; these are the rules that are not dynamic and never change. When I recreate the ManagedFusion.Rewriter.txt file I read this file first and then append all my dynamic content at the end of the file.

privatevoid RebuildRedirects() { StringBuilder sb = new StringBuilder(); using (TextReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~") + "RewriteBase.txt")) { sb.Append(reader.ReadToEnd()); } string rewriteRule = "RewriteRule ^{0}(.*)$ /ProjectCategory.aspx?Category={1}&Project={2} [NC,L,QSA]"; foreach (Category category in Items) { foreach (Project project in category.ProjectItems) { sb.AppendLine(string.Format(rewriteRule, project.FriendlyUrl, category.ID, project.ID.ToString())); } } using (TextReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~") + "RewriteBacklinks.txt")) { sb.Append(reader.ReadToEnd()); } using (FileStream writer = File.OpenWrite(HttpContext.Current.Server.MapPath("~") + "ManagedFusion.Rewriter.txt")) { lock (writer) { writer.Write(ASCIIEncoding.UTF8.GetBytes(sb.ToString()),0,sb.ToString().Length); } } }

The code above also caters for rewriting of ‘backlinks’ from the previous incarnation of the web site to keep the SEO stats up and keep Google happy.

And that’s pretty much it. A fully dynamic site with friendly urls.

BondiGeek