Redirecting Wordpress Feeds to Feedburner
Written by Brian on December 6, 2008 – 7:30 pm -
Continuing my attempts to improve this site, I decided to embark on creating feedburner feeds for each sub-site. Then, I needed to re-direct my Wordpress feed files to feedburner.
Turns out it wasn’t quite as easy as I hoped. There’s a Wordpress plugin available to redirect your feed to Feedburner, but this only redirects the main feed and the comments feed. No dice for categories.
I found a few people suggesting an alternative: .htaccess rewrites. I never liked working with .htaccess, mostly because I never liked working with regex. But what are ya gonna do?
An .htaccess Alternative to the Plugin
I found an example of a .htaccess solution at Persihable Press.
For a full explanation, head over to the original article. But in the meantime, here’s the .htaccess code he suggested:
# temp redirect all wordpress feeds to feedburner RewriteEngine on RewriteCond %{REQUEST_URI} ^/?(feed.*|comments.*) [NC] RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC] RewriteRule ^feed/?.*$ http://feeds.feedburner.com/perishablepress [L,NC,R=302] RewriteRule ^comments/?.*$ http://feeds.feedburner.com/perishablepresscomments [L,NC,R=302]
As I understand it, this is more or less a three step process.
First, the regex catches all requests for a URI that includes feed or comments (i.e. your RSS feed). Then, it checks if the user agent is FeedBurner. The FeedBurner bot is allowed to access the original feed, but everybody else should be tossed over to the Feedburner site.
Finally, it sends the user to the appropriate Feedburner URL, based on the request URI.
Adding Category Feeds
That, of course, does the same thing as the plugin. It redirects the site feed and the comments feed, but it doesn’t help you redirect your categories.
For me, each parent category is like it’s own site, so that doesn’t help. I’d like you to be able to subscribe to the “Nerds at Work” feed about web development without being bored by all my ranting on education.
Luckily, somebody commented on the original article and left a suggestion as to how to redirect the category feeds. I used that to create my own .htaccess file, and everything seems to work hunky-dory.
You don’t need to re-write any of the conditions, because that regex will already flag the category feeds. All you need to do is add a few extra rewrite rules, based on the new URIs and provide the appropriate Feedburner URL.
In general, that rewrite rule should look like this…
RewriteRule ^category/nerds-at-work/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-work [L,NC,R=302]
Replace ‘nerds-at-work’ with your own category slug, and replace the full URL with the URL to your Feedburner feed.
I had some trouble with this at first, but I think the problem was due to positioning. In the end, I added all of the category specific re-write rules after the general rewrite rule. When I placed them first, it didn’t work. Might just be that I’m a regex/htaccess newb, though.
Here’s the full .htaccess file that I’m using, including what Wordpress generated for the pretty-urls.
# Redirect Wordpress Feeds to Feedburner RewriteEngine on RewriteCond %{REQUEST_URI} ^/?(feed.*) [NC] RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC] RewriteRule ^feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-sitewide [L,NC,R=302] RewriteRule ^category/nerds-at-work/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-work [L,NC,R=302] RewriteRule ^category/nerds-at-play/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-play [L,NC,R=302] RewriteRule ^category/teach-them-well/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-teach [L,NC,R=302] RewriteRule ^category/life-of-brian/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian [L,NC,R=302] # BEGIN WordPress RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
Good luck, and hopefully you’re more experienced with htaccess/regex than I am.
Posted in CMS Tricks, Nerds at Work | 1 Comment »
Tags: .htaccess, Feedburner, Wordpress
Find that post enjoyable or informative? Why don't you subscribe to the feed for Nerds at Work. Or, subscribe to the site-wide feed and catch up on all my antics.
1 Trackbacks/Pingbacks
-
Pingback:
This Life of Brian » Blog Archive » Grr… Feedburner.
December 13, 2008
