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”:, 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)?/?[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”: 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)?/?[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”: for this article was “found”: in “many”: “places”: Here are some other articles you might want to read:
* “Apache Module @mod_rewrite@”:
* “WordPress FeedBurner Plugin”:
* “Why Redirecting Your Feed Isn’t Such a Great Idea”:
* “Ciao, FeedBurner”:

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!