Running WordPress Feeds Through FeedBurner

I like stats. I use Google Analytics to track standard web stats, but it relies on javascript and can’t track subscriptions to my RSS feeds. Enter FeedBurner.

FeedBurner lets you publicize, optimize, analyze, and monetize your RSS feeds – basically putting your standard RSS feed on steroids. You tell FB where it can find your blog feed (mine’s at http://adamstiles.com/feed/) and it produces a souped up version that can be downloaded from a FeedBurner URL (e.g. http://feeds.feedburner.com/adamstiles). Once you have this new feed URL, you just need to get your subscribers to download it from the new location. Easy enough for new subscribers, but what about existing ones? I want my stats to include all readers, not just existing ones.

A little WordPress background is in order. WP processes all pages on your blog, including your feeds, through a PHP file called index.php. It uses a couple of mod_rewrite rules to make this happen.

#
# Apache mod_rewrite rules that rewrite URLs from:
#
# OLD: http://adamstiles.com/feed/
# NEW: http://adamstiles.com/index.php?feed=feed
#
# OLD: http://adamstiles.com/feed/rss/
# NEW: http://adamstiles.com/index.php?feed=rss
#
# Etc… for rdf, rss2, atom
#
RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

Its important to get this to avoid a gotcha later. Your subscribers download your feed from a URL that looks like this http://adamstiles.com/feed/ but WP processes that request like this http://adamstiles.com/index.php?feed=atom. Your feed subscribers will use the first URL, even though WP uses the second internally. Nobody subscribes to the index.php?feed=atom version of your feed but we’ll use that when we tell FB where it can find your feed.

Now that that’s out of the way we can get started.

Step 1: Setup Your FeedBurner Feed

The first thing you need to do is tell FeedBurner where to find your feed. There is an important gotcha here – use a WP feed url with index.php in it, don’t use the rewritten WP feed URL. In my case, I told FB that my feed was located at http://adamstiles.com/index.php?feed=atom. FB now makes my souped up feed available at http://feeds.feedburner.com/adamstiles. The reason you need to tell FB to use the index.php url and not your rewritten URL is that we’re going to tell Apache to redirect subscribers to our old feed URL to the new FeedBurner URL. See the problem? If FB is grabbing the URL from the rewritten URL, but we’re redirecting the rewritten URL to FB, it gets caught in a loop and never actually gets any feed content. Make sure you’re using the index.php?feed=something URL when setup your account with FB.

Step 2: Redirecting Old Subscribers to the New URL

We’ll use some custom mod_rewrite rules to redirect feed readers from the old WordPress feed URLs to the new FeedBurner URLs. Modify the feed-related rules in your .htaccess file to redirect to FeedBurner.

#
# Replaced /index.php?feed=$1 with my FeedBurner URL
# The R in brackets tells apache that this is an external redirect
# The L means this is the last rule for processed for the URL
# http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
#
RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/adamstiles [R,L]
RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/adamstiles [R,L]

I also updated some other rules that I originally setup when I moved to WordPress from TypePad:

RewriteRule ^adam/atom.xml$ http://feeds.feedburner.com/adamstiles [R,L]
RewriteRule ^adam/index.rdf$ http://feeds.feedburner.com/adamstiles [R,L]

After this, test the rules. Go to your old, rewritten feed url (e.g. http://adamstiles.com/feed/) in a browser and you should be redirected to your FeedBurner URL. FB will detect that you’re using a browser to display your feed and it will add some markup to it to make it easy to read (not just XML).

Step 3: Making Redirects Permanent

This step is optional but some will find it useful. At this point your redirects are temporary – feeds readers will still come to you first and they’ll be redirected to the FeedBurner URL each time. If you use a permanent redirect, many feed readers will update their subscription data so they go directly to the FB URL and don’t have to come to your first. To do this, you need to change your rule modifiers from [R,L] to [R=permanent,L].

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

Tags: , , ,

Advertisements

10 thoughts on “Running WordPress Feeds Through FeedBurner

  1. Using FeedBurner to manipulate the feed, by entering additional content, ads, or doing some fine-tuning, I can understand. Those are big advantage of the service, which certainly may offset the potential problems with having your feeds routed through a third party.
    But the opening phrase of the post make it sound like you mainly do it for the stats. Which makes me wonder, what stats can FeedBurner provide you, which you don’t have otherwise?

    Even assuming you don’t host WP on your own machine, most hosts I know give you access to your server logs, so you can get from that what is being used to poll your feed URI… Is there any statistic FeedBurner provides which cannot be taken from these, through any statistics package you may use to monitor them, just like for other links on the site?

  2. Rewrite feed to new address as source for FeddBurner is work! But my http://www.getnew.biz/feed/ and redirect don’t work. Help please…

    My full .htaccess file:
    ==========================
    # BEGIN WordPress
    RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/newbusiness [R,L]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/newbusiness [R,L]
    # END WordPress
    ==========================

  3. Assev – Did you save a copy of your old .htaccess file? The link to http://www.getnew.biz/feed/ should be redirected to the index.php?feed=feed URL instead of to FeedBurner because your first rule takes precedence over your third rule which overlap. I know why its not going to FB, but not sure why you are getting a 404… because it should still go to index.php locally. Did you old .htaccess work?

    Adam

  4. Yaron – good question – I should have addressed that better in my post. Bloglines, My Yahoo!, NewsGator Online, etc, include subscriber counts in the user agent when they download your feed. FeedBurner is smart enough to parse this and include it in my statistics, while normal web stats apps aren’t smart enough to do this. I could have gotten the stats I wanted from my own web stats, but that would require more digging than I wanted to do. For me, FeedBurner makes my stats much more accessible that through normal web stats apps.

    Adam

  5. Adam: my old .htaccess very simple – it is exist after install and activating permalink structure. Is work for http://www.getnew.biz/feed/

    My old .htaccess file:
    =================
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php

    # END WordPress
    =================

  6. Aseev – That worked for your permalink structure? Usually WP rules are much more explicit than those.

  7. Not sure what to tell you Aseev — don’t think this method will work if you’re not using standard WordPress .htaccess rewriting.

  8. Adam, I suspect he’s using WP 2.0 which does indeed work fine that way – it does quite a bit without .htacess now.

Comments are closed.