Redirecting WordPress Feeds to FeedBurner

If you want to simplify delivery, management, and analysis of your site’s feeds, “FeedBurner”:fb is a great solution. This page will give you a quick summary of “what FeedBurner is about”:fbabout. One of my favorite features (complete list of “features”:fbfeat) is “SmartFeed™”:smart, an option that provides a _subscriber-aware_ version of your feed to an aggregator, regardless of the feed format you are currently publishing. That means that if you serve an Atom feed, but a subscriber’s reader doesn’t support Atom, SmartFeed™ serves up your feed as RSS(Real Simple Syndication), or some other format on-the-fly! Burning a feed is simple, the FeedBurner site walks you through the process. Add a nice little button to your site, and you are done… almost.

Here’s the catch. Most content management systems like “WordPress”:wp generate several feeds in a variety of flavors, each linked to your site via a @<link>@ element like this:




Every newsreader that uses auto-discovery to subscribe to your feed, gets the URL(Uniform Resource Locator) for your feed from these @<link>@ elements, completely ignoring the cute little FeedBurner button you proudly display on your page.

Assuming the FeedBurner URL to your new feed is, “mywildfeed”, you could simply change each element to look something like this:




But changing @<link>@ elements has a downside:
# An upgrade to your CMS(Content Management System) could overwrite your template reverting the @href@ attribute to it’s previous value
# If you decide to stop using FeedBurner, you could have a large subscriber base that would need to re-subscribe using a new URL.

You could create a new feed for FeedBurner to consume (not exposed in a @<link>@ element), and use an Apache redirect to point request for your old feeds to your new FeedBurner feed as outlined in this “post”:http://forums.feedburner.com/viewtopic.php?t=17, but you are subject to the same disadvantages as the previous example.

h3. Solution

To avoid some of the faults with the methods listed above, I choose to use Apache @mod_rewrite@ directives to redirect requests for any feeds straight to FeedBurner. A couple of entries in @.htaccess@ are all you need[1]:

# FeedBurner Redirect
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !^FeedBurner.? [NC]
RewriteRule ^(feed|rdf|rss|rss2|atom)/?(feed|rdf|rss|rss2|atom)?/? 
http://feeds.feedburner.com/mywildfeed[R,L]

If you are playing along at home, we’ll look at the important entries and explain what’s going on.

First we use @RewriteCond@ to make sure that the “user agent”:http://www.answers.com/user%20agent requesting the feed is *not* the FeedBurner bot[2]. This is significant, because if it is FeedBurner, we *do not* want to redirect, or we effectively create a circumstance where the service consumes itself (ugly).

RewriteCond %{HTTP_USER_AGENT} !^FeedBurner.? [NC]

Now, and only if the condition above is true, the @RewriteRule@ that does the real work:

RewriteRule ^(feed|rdf|rss|rss2|atom)/?(feed|rdf|rss|rss2|atom)?/? 
http://feeds.feedburner.com/mywildfeed[R,L]

Without going into a long-winded tutorial on “regular expressions”:regex, this rule catches the request for any feed offered by WordPress, and redirects it to the FeedBurner URL.

h3. Benefits

There a several benefits to this solution, most notably:
# It doesn’t matter how a reader is subscribed to a feed, they are quietly whisked away to the FeedBurner URL when ready to consume.
# Since the regular expression in the @RewriteRule@ catches all the ways feeds are available in typical @<link>@ elements, you need not worry about changing your template.
# To discontinue using FeedBurner, or change to a similar service, simply eliminate or modify the entries in the @.htaccess@ file.

All of this adds up to a solution that is easy to maintain, and _never_ results in a disruption to the subscriber base.

h3. References

“Inspiration”:http://www.burningdoor.com/feedburner/archives/000425.html for this article was “found”:http://www.cre8d-design.com/blog/2006/01/26/are-you-funnelling-all-your-subscribers-through-feedburner/ in “many”:http://www.stopdesign.com/log/2005/04/20/feedburning.html “places”:http://www.chaddickerson.com/blog/?p=37. Here are some other articles you might want to read:
* “Apache Module @mod_rewrite@”:http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
* “WordPress FeedBurner Plugin”:http://orderedlist.com/articles/wordpress-feedburner-plugin/
* “Why Redirecting Your Feed Isn’t Such a Great Idea”:http://www.symphonious.net/2005/09/30/why-redirecting-your-feed-isnt-such-a-great-idea/
* “Ciao, FeedBurner”:http://www.burningdoor.com/feedburner/archives/001251.html

h4. Footnotes

fn1. Keep in mind I use WordPress to power my blog, you may require slightly different syntax.

fn2. I know, the @RewriteCond@ is actually parsed after the @RewriteRule@… I’m trying to keep it simple!

[fb]http://www.feedburner.com
[fbabout]http://www.feedburner.com/fb/a/about
[fbfeat]http://www.feedburner.com/fb/a/publishers
[smart]http://www.burningdoor.com/feedburner/archives/000520.html
[wp]http://www.wordpress.org
[regex]http://www.regular-expressions.info/