Redirecting WordPress Feeds to FeedBurner
If you want to simplify delivery, management, and analysis of your site’s feeds, FeedBurner is a great solution. This page will give you a quick summary of what FeedBurner is about. One of my favorite features (complete list of features) is SmartFeed™, 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, 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 generate several feeds in a variety of flavors, each linked to your site via a <link> element like this:
<link rel="alternate" type="application/rss+xml" title="RSS 2.0"
href="http://www.example.com/feed/" />
<link rel="alternate" type="text/xml" title="RSS .92"
href="http://www.example.com/feed/rss/" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3"
href="http://www.example.com/feed/atom/" />
Every newsreader that uses auto-discovery to subscribe to your feed, gets the URL 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:
<link rel="alternate" type="application/rss+xml" title="RSS 2.0"
href="http://feeds.feedburner.com/mywildfeed" />
<link rel="alternate" type="text/xml" title="RSS .92"
href="http://feeds.feedburner.com/mywildfeed" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3"
href="http://feeds.feedburner.com/mywildfeed" />
But changing <link> elements has a downside:
# An upgrade to your CMS 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.
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 need1:
# 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 requesting the feed is not the FeedBurner bot2. 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, this rule catches the request for any feed offered by WordPress, and redirects it to the FeedBurner URL.
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.
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
Footnotes
1 Keep in mind I use WordPress to power my blog, you may require slightly different syntax.
2 I know, the RewriteCond is actually parsed after the RewriteRule… I’m trying to keep it simple!

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.