Scott Hanselman

Permanent Redirects with HTTP 301

October 20, 2005 Comment on this post [5] Posted in ASP.NET | DasBlog | XmlSerializer | HttpModule
Sponsored By

The very latest version of DasBlog uses a 301 Permanent Redirect to send aggregators to my feed's new location at FeedBurner. Because it's a 301, most aggregators automatically update their data with a new location and don't bother asking for the original one again.

Here's how to do a hardcoded 301 redirect within ASP.NET:

response.StatusCode = 301;
response.Status = "301 Moved Permanently";
response.RedirectLocation = "";

You can also do this, which I see a lot while looking at the bathroom wall of code folks call Google Groups:


They pretty much do the same thing, but color me reactionary, I like to use the APIs available just for cleanliness's sake.

Of course this is a redirect, not an URL rewrite. Redirect's go all the way back to the requester and provide a hint on where to go next, while rewrites leave the requested the URL the same and tell the web server that something else was requested.

DasBlog has a lovely rewriting HttpModule that you're welcome to use. Erv Walter extended it and added support for redirecting URLs as well as fixing host names. These things are particularly useful if you do not have direct access to your web server's administrative console.

Fritz Onion, my hero but a man I've never met, also has a great redirecting module that's very elegant and coincidentally uses Craig Andera's "Only Configuration Section Handler You'll Ever Need" which is a fantastically snazzy chunk of code that I just can't seem to get folks here at work to latch onto.

Whichever one of these models you use, or if you write the redirect yourself, remember the "principle of least surprise."

If I type in the URL, I don't care how you get me there, just get me there.

UPDATE: It was asked in email "Whats a [good] way around postback URLs getting f'ed up when rewriting URLs." To answer that, I point you to an oldy, but a goody, a blog post with a clever title that no one really every appreciated, IMHO: "Postbacks for Algernon"

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
October 21, 2005 6:50
The link to Craig Andera's "Only Configuration Section Handler You'll Ever Need" has apparently changed. Here is the current link:

October 21, 2005 7:50
It's funny that you've never met Fritz Onion, because I'm pretty sure you guys both had cabana sessions about 30 feet away from each other at TechEd 05 at around the same time. So close...
October 21, 2005 23:22
With your own domain, you of course have the option of 301'ing aggregators to feedburner.

What if at some point you want to move from feedburner back here or to some other service? Do they allow you to 301 away from their systems, or are you locked into feedburner now?
October 22, 2005 1:16

DasBlog can do these 301 redirects even if the user doesn't control his own domain - they just need to control their app/vdir.

I'm checking into the details, but apparently FeedBurner WILL redirect your feedburner feed to another feed for up to 30 days if you decide to move away.
January 17, 2006 23:53
Awesome! I thought I remembered reading somewhere that a permanent automatic redirect could be done. It was on your blog, of course.

Thanks, Scott

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.