FeedBurner htaccess voodoo with WordPress 2

by oneafrikan on April 19, 2006

If you use FeedBurner to burn your feeds, then you probably want FeedBurner to retrieve the feeds from your site as normal, but you want _ALL_ your visitors to read your feed using FeedBurner.

The WordPress .htaccess solution between versions 1.5.x and 2.x has changed somewhat, so when I simply imported my old htaccess file after doing a full upgrade to the shiny new WP version, things didn’t work as planned… which is cool, since I’d been doing some work with htacess already, and felt I was ready to play with the apparent voodoo ;-)

So basically my logic went like this:

  1. Turn the rewrite engine on
  2. Set the rewrite base url to “/”
  3. Make sure that any request to http://oneafrikan.com is redirected to http://www.oneafrikan.com
  4. Do the same for the feed url
  5. Set the correct feed url for feedburner
  6. Set the correct feed url for everyone other than feedburner
  7. Set the correct comments feed url for feedburner
  8. Set the correct comments feed url for everyone other than feedburner
  9. Start processing for WordPress
  10. And then do some anti-spam stuff that isn’t really the point of this post

So now what happens is that whenever someone clicks on http://www.oneafrikan.com/feed/ or http://www.oneafrikan.com/comments/feed/, they get redirected to a feedburner feed that they can read and also subscribe to…

The flip side of this is that because I’m playing around with new themes for my blog and editing stuff, doing the redirection in htaccess is far easier for me than it is to go and manually edit files for each template.

The end result went quicker than I thought and although this is by no means the real .htaccess voodoo that is really possible with mod_rewrite, I did find it easier than I thought (but that may be because I’ve just done a project using .htaccess to create SE friendly URL’s) it would be.

So, in the spirit of sharing the love, here is the relevant code for you to cut and paste and do with as you like:

RewriteEngine On
RewriteBase /

### set all page requests to go to www.oneafrikan.com
RewriteCond %{HTTP_HOST} ^oneafrikan\.com$ [NC]
RewriteRule ^(.*)$ http://www.oneafrikan.com/$1 [R=301,L]
# same for feedburner
RewriteRule ^http://oneafrikan.com/feed?$ http://www.oneafrikan.com/feed/ [R]

##### feedburner
### redirect for feedburner feed
RewriteCond %{HTTP_USER_AGENT} ^FeedBurner.*$
RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
RewriteCond %{HTTP_USER_AGENT} ^FeedBurner.*$
RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

# redirect for users not subscribed
RewriteCond %{HTTP_USER_AGENT} !^FeedBurner.*$
RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/oneafrikan [R=permanent,L]
RewriteCond %{HTTP_USER_AGENT} !FeedBurner.*$
RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/oneafrikan [R=permanent,L]

### redirect for feedburner comments feed
# http://feeds.feedburner.com/oneafrikancomments
RewriteCond %{HTTP_USER_AGENT} ^FeedBurner.*$
RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?feed=$1&withcomments=1 [QSA,L]
RewriteCond %{HTTP_USER_AGENT} ^FeedBurner.*$
RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ /index.php?feed=$1&withcomments=1 [QSA,L]

# redirect for users not subscribed
RewriteCond %{HTTP_USER_AGENT} !^FeedBurner.*$
RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/oneafrikancomments [R=permanent,L]
RewriteCond %{HTTP_USER_AGENT} !FeedBurner.*$
RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/oneafrikancomments [R=permanent,L]
##### /feedburner

# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Hope that helps someone ;-)
Does anyone have any better solutions or do things differently?


Youre using Steve Smith’s WP-admin skin, but don’t know about his Feedburner plugin?! Shame on you…. :-)


Redirect’s all your WP RSS feeds to Feedburner.

by JBagley on April 20, 2006 at 7:58 am. Reply #

Hey Jason

Ahuh! You caught me out ;-) The Tiger Admin plugin is really great ;-)

I did have a loot at Steve’s feedburner plugin, but in the end opted to do it server side before WP even smells it, just ‘cos I prefer it that way. Steve mentioned that “… instead of making the edits to the core WordPress files, I decided to make it a plugin …” – using htaccess means that whatever theme you use, you don’t need to do any code edits anywhere, you don’t need the plugin processing overhead (not that that’s an issue really), and if you’re really lazy you don’t even need to write a plugin ;-)

The other bonus with htaccess is that you can do a permanent redirect at server side, which is cool ‘cos with most feed readers it will upfate their feed locations…

Anyways, just my way of doing it, not necessarily the absolute or best way of doing it ;-)

by Gareth Knight on April 20, 2006 at 10:44 am. Reply #

I just stumbled across this and it’s what I need. However, I have set up an individual feed for each category on my site because my site covers so many topics that no few people want to read it all. Using your code points all the feeds to my main feedburner feed.

I’d like to point my full site feed to my feedburner feed and set up a few category feeds to point to their corresponding feedburner feeds. The remaining feeds shouldn’t point anywhere except to themselves.

I don’t know a thing about .htaccess. Can you either point me to a plain English document that’ll help or tell me how to modify your code above to solve my problem?

Any assistance is greatly appreciated. Thanks!

by Maria on February 1, 2007 at 3:02 am. Reply #

Why the need for so many rules? Can you explain this in detail?

I implemented the redirect with much lesser rules. Check out my post.

by Ajay on March 16, 2007 at 6:30 pm. Reply #

Leave your comment


Required. Not published.

If you have one.

Protected with IP Blacklist CloudIP Blacklist Cloud