Permanent Redirects with HTTP 301
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 = "http://www.hanselman.com/blog";
response.End();
You can also do this, which I see a lot while looking at the bathroom wall of code folks call Google Groups:
Response.AddHeader("Location","http://www.hanselman.com/blog");
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.
About Newsletter
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?
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.
Thanks, Scott
Comments are closed.
http://pluralsight.com/wiki/default.aspx/Craig/XmlSerializerSectionHandler.html
Harry