Subscribe to RSS Subscribe to Comments

Geek On The Mountain

For a transcript of today's post, please see below

"I come out here a lot and say we got a great show tonight: Wrong 90% of the time.....95%....Do I hear 98?"
-- Conan O'Brien - 5/6/2004



Feedburner and WordPress

I started using feedburner the other day. It’s a service that will essentially compile statistics for your feeds. I also have to say that it was really easy to setup in WordPress (it should be really easy to setup anywhere…) and I’ll explain exactly how to do so.

Feedburner gives you stats on your feeds. It can actually tell you how many people have subscribed to your feeds and what reader they’re using. It also recognizes hits from browsers and from bots (and does not include these in the number of people subscribed). It sounds like the pro version gives some nifty stats, although at just under $5 a month, I don’t care enough to find out anytime soon. There are various things that feedburner can do, but besides stats the one I find the most interesting is that when it detects a browser accessing the feed, it will spit out an actual page that explains exactly what a feed is and it shows the feed’s content in a legible form. This is by far better than a useless xml display that visitors would otherwise see. I don’t exactly have any high-traffic feeds, but when you sign up with them they’re essentially hosting your feed, so there’s the potential for saving some bandwidth with the whole deal as well. (they’re really making a copy of your feed and serving it up…your feed is still out there, but there’s also a feedburner feed with the same content)

The whole thing is really simple. Just go to their site, sign up and input your feed’s URL. I’d recommend not actually giving them your feed’s URL though. Or at least, not what it is just now…

Unless your site is brand spanking new, it’s likely that you have at least a few people who already subscribe to your feeds. If you set yourself up through feedburner, you want these people to use the feedburner feed and not the one from your site (they’re identical, of course, but feedburner can only track stats from it’s own feed). You have two options here. You can either (try to) tell them about the new feed and then hope they switch over, or you can make them do it. The latter option is of course the preferable one, and since both feeds are identical, they won’t even know they’ve been switched (remember those old Folger’s crystals commercials? :) ).

The basic idea is that you need to make your current feed’s URL point to the feedburner feed. You cannot therefore tell feedburner to use your current feed’s URL. What would happen? Well, yoursite.com/feed points to feeds.feedburner.com/yoursite which then looks to yoursite.com/feed for the feed data. Of course this points to……you get the idea. It doesn’t really work. You need to make your actual feed publish at some other URL, and tell feedburner to use that.

In WordPress, this is dirt simple. As such, I’ll give along winded explanation as to exactly what’s going on. It’ll be informative at least….
I’ll mention upfront as well that there is a codex entry on how to do this (it’s just doesn’t tell you exactly what’s going on under the hood like I will) and also there’s a feedburner plugin as well. For the life of me, I can’t imagine why you’d use the plugin though since it is so easy to do by hand. The only advantage of the plugin is that you don’t have to edit .htaccess. Of course, editing .htaccess isn’t any more difficult than starting up your FTP client, which you have to do in order to upload the plugin anyways…

As you might know, WordPress uses mod-rewrite to simulate a directory structure for your blog. You don’t have to use this, but most people do. Mod rewrite is an awesome Apache module that just rewrites one URL to another. Even though it’s so simple, it actually has many uses, including hotlink protection. For all you could possibly like to know about how it works, check out the official docs.

WordPress likes to put your feeds at yoursite.com/feed. If you’re in this same boat, then you’ll find a line like this one in your .htaccess file (in your root web directory… make a backup before you edit this puppy too. If you get one character wrong in it, it can shut down your whole site).

RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

And what the hell does that mean? This particular line says that when a URL is requested from the server in the form of /feed/feed OR /feed/rdf OR /feed/rss OR etc… then it will actually fetch up /index.php?&feed=feed OR /index.php?&feed=rdf OR etc. (the $1 gets replaced by whatever item from within the parenthesis happens to apply) The funky strings are regular expressions. If I’ve totally lost you, don’t worry. You don’t have to know all the details here. Just know that what it’s doing is replacing the first item with the second item.

You might notice at this point that what this is something with index.php when someone goes looking for a feed. The ‘?’ represents input that’s being sent to index.php. Basically, the URL is requesting the feed from index.php. This is how everything works in WordPress. All your posts and everything actually get extracted from index.php in this manner. We can use this to our advantage.

I changed the line you see above to this line in my .htaccess:

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

This means that when someone tries to access a feed, they get redirected to my feedburner feed instead. Then, I told feed burner to use the feed at

http://www.slaad.com/index.php?&feed=feed

So feedburner gets the actual feed straight from the horse’s mouth, while everyone else who is used to my feed being located at slaad.com/feed is now using the feedburner feed. Easy easy.

You’ll see another line in .htaccess that looks just like the one I just showed you except instead of starting off “^feed/(feed|rdf|….” it starts “^(feed|rdf|…”. I’d change that one just like we did the one before. There’s also an entry for the comments feed, but that’s another feed altogether…

I’m also assuming that you don’t care to distinguish between your different types of feeds (feedburner can actually take one feed that you send it and convert it to the other types). If you wanted to add each feed separately to feedburner, you can. You’d just need to change the above lines so that they’d re-write each type to the corresponding feedburner feed. If it’s still all Greek and you want to do that, check out that regular expressions site.

The really nice thing about redirecting like this is that no only do your current readers get seamlessly switched over to the new feed, but the links on your site should also redirect to the new feed as well. You don’t have to change a bunch of different stuff in a bunch of different places.

The one last thing you might wonder is how does it keep it’s feed up to date with yours. You ping feedburner when you update, that’s how. If you’re using WP, then you probably ping ping-o-matic (it does this by default) already, and ping-o-matic will ping feedburner for you. How does it work if you don’t ping it? You’ve got me. I’d guess that maybe it just checks in every so often. I’m really not sure….I just ping, it’s easier.

No Tags

Popularity: 63% [?]



No comments yet. Be the first.

Leave a reply

Based on FluidityTheme Redesigned by Kaushal Sheth