I'd mentioned previously... perhaps several times... that after several upgrades of my home blog software (
dottext ->
CS1.1 ->
CS2.0)
and successive reconfigurations of said multi-user blog software to run
in a "single blog" configuration for my personal use, I've got a lot of
page requests coming into the site that are no longer pointing at valid
urls for my current side.
Through the upgrades, the locations of
my blog, images, posts, and all that junk has changed ever so slightly
in the past 2 or 3 years. An extra virtual directory here... a changed
gallery name there... and voila, any favorites people had set, or any
urls that have been stored in search engines from old web crawls are
now busted up.
I'd go puttering around the CS config files to
try and fix these issues, but frankly they're almost a black box. I
hesitate to make many additional modifications to the config files that
handle these url redirections because I hate having to spend more time
than I absolutely need to during a CS upgrade. Any changes I make to
the config files has to be re-changed, reviewed, and tested after an
upgrade.
That's frankly too much work.
SO!
What
I've gone and done is build a little add on Geeqs.Net.UrlRewriter.dll
(see attachment to this post for the binaries) for ASP.Net 1.1 websites
that anyone can use to reformat an incoming request, valid or not, to
transfer, redirect or silently hand-off to another valid URL. It could
be on the same site, or on another server entirely.
The DLL took
me about 3 to 4 hours to write in C#. Most of this time was actually
spent learning what I needed to know about regular expressions. ...
What? You didn't know how to use regular expressions?That's right. RegEx didn't come along back when I was gettin' my schoolin' done, sonny boy!
The basics I leared from
a sample posted over at
15seconds.com that was written by
Robert Chartier
that shows you how to use an HTTPmodule handler to capture and modify a
request coming into ASP.Net. The rest was basic handling of RegEx
expressions and reading these settings from the web.config file.
Now
that I'm done and it's added to my CommunityServer directory any
requests coming in to Urls that no longer exist on my new blog are
being redirected to the correct Url. Since the replacement operations
are using regular expressions I can use pattern matching to redirect a
general type of request to another valid resource.
For example, an invalid request to
http://blog.geeqs.net/photos/dottextweb/picture227.aspx
should actually be going to
http://blog.geeqs.net/photos/blogimages/picture227.aspx.
So
I've got a "rule" stored in the web.config file that will be used to
search for this pattern and replace the incorrect elements with the
correct elements. I've got 6 rules set up to redirect various
incorrect incoming requests to valid urls so they don't get a HTTP 404
error message.
I expect that the exceptions report I get for
missing file requests coming into my server will virtually dry up now,
and all of those searches from Google, Yahoo, Ask.com, and various and
sundry, will now direct to valid resources.
Yee haw!
(I
wish I knew why these search sites didn't just expire those results in
their search engines... I mean, they were GONE for months!)
I've
posted the binaries and a quick and dirty text file describing how to
install and use the module to this post. If you know regular
expressions already, it'll be dead simple to implement. If anyone
wants it I'll gladly hand you the source code as well. Good luck and
let me know how it goes if you use it!
Posted
Apr 18 2006, 11:49 PM
by
Keith Reid