URL Rewriting with ASP.NET
Posted on February 1, 2007 1:25 PM
I found an article written by Richard Birkby on The Code Project website that explains how to do URL rewriting using ASP.NET.URL rewriting is commonly used to make URL's that look like:
http://rasputin.dnsalias.com/default.aspx?year=2006&month=1
look like:
http://rasputin.dnsalias.com/articles/2006/1/January2006.aspx
Mostly, the difference between the two is that the first one can get easily mangled, by both humans and intrusive email providers *cough* hotmail sucks *cough*. More importantly, the second format is more acceptable to search engines. Apparently, search engines are less likely to care what comes after the question mark in the first form. I just thought it would be cool to figure out how to do it, because that's the kind of guy that I am.
Taking a look at the article from Code Project and downloading the source files, the process is straight forward. For my own purposes, I changed the code here and there to make it work the way I want. Specifically, I wanted to implement this on a server that I do not necessarily have total access to. Mr. Birkby has you "copy" the compiled binary file into the windows/assembly directory. I will admit that I don't fully understand the purpose of this, but I do know that my hosting service probably isn't going to go for that.
In the web.config file, I replaced the following:
| Code: |
<section name="urlrewrites" type="ThunderMain.URLRewriter.Rewriter, ThunderMain.URLRewriter, Version=1.0.783.30976, Culture=neutral, PublicKeyToken=7a95f6f4820c8dc3"/> |
with
| Code: |
<section name="urlrewrites" type="ThunderMain.URLRewriter.Rewriter, ThunderMain.URLRewriter, Version=1.0.783.30976, Culture=neutral"/> |
Because I am not going to copy the binary into the assembly directory, I also removed these lines from the Rewriter.cs file:
| Code: |
[assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile(@"keyfile.snk")] [assembly: AssemblyKeyName("")] [assembly: AssemblyVersion("1.0.783.30976")] |
After compiling the modified Rewriter.cs file I copied the DLL into my /bin directory on the webserver.
In his article, Mr. Birkby mentions that to have the url rewriter process all file extensions (not just .aspx) you'll have to add wildcard mapping to point to the ASP.NET ISAPI extension. While I might consider adding mapping for .asp or .html I want to stay away from adding a mapping for .* as he suggests. I may have done something wrong but that seems to mess up for urls that have no extension like:
http://rasputin.dnsalias.com/photos and http://rasputin.dnsalias.com/football
In any case, I don't mind keeping the .aspx extension, I just wanted to get rid of all the other weird little characters.
Add/View Comments (1) Tags: asp.net, search engine optimization, url rewriting
