Geeqs.Net Community Server
Keith Reid's public web log. Go Geeq or Go Home!

Redirection of a Misdirected Url?

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
Filed under:

Comments

geeqs wrote
on 04-20-2006 11:50 PM
Geeqs.net Url Rewriter
TrackBack wrote http://communityserver.org/forums/thread/516847.aspx
on 04-29-2006 3:23 PM
Tabs wrote re: Redirection of a Misdirected Url?
on 05-15-2007 9:02 AM

Hi,

Picked up on this post from a search on the CS forum. I've enabled a root blog on my site and now have a few dead links from google/msn/yahoo etc.

As I'm running CS2007 I can't use your redirector. Did you ever port this over to .NET 2.0?

Keith Reid wrote re: Redirection of a Misdirected Url?
on 05-15-2007 8:32 PM

I never updated it because I assumed (possibly incorrectly) that it would work as-is on .Net 2.0 (which my site is currently running under).

Are you sure you've set up the REGEX rules and config file settings as described in the ZIP?

Tabs wrote re: Redirection of a Misdirected Url?
on 05-16-2007 3:57 AM

My bad, I presumed it wasn't compatible with .NET 20.0 <slaps face>

I'll get it uploaded and tested. I basically just need to map incoming requests for:

http://tabsy.net/blogs/tabs/archive/<post link>

To

http://tabsy.net/archive/<post link>

Add a Comment

(required)  
(optional)
(required)  
Remember Me?