In a previous article, I explain how to redirect your WordPress feeds to Feedburner. Redirecting your WordPress feeds to Feedburner enables you to take advantage of their many freely provided, highly useful tracking and statistical services. Although there are a few important things to consider before optimizing your feeds and switching to Feedburner, many WordPress users redirect their blog’s two main feeds — “main content” and “all comments” — using either a plugin or directly via htaccess. Here is the htaccess code as previously provided here at Perishable Press:
# temp redirect wordpress content feeds to feedburner
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/perishablepress [R=302,NC,L]
</IfModule>
# temp redirect wordpress comment feeds to feedburner
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^comments/feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/perishablepresscomments [R=302,NC,L]
</IfModule>
The first code block redirects main content feeds to Feedburner, while the second block does the same for the main comments feed. The only editing required for either of these redirects is for the Feedburner URL itself; that is, edit the “http://feeds.feedburner.com/perishablepress” and/or “http://feeds.feedburner.com/perishablepresscomments” to match your own address. With this htaccess code in place, your feeds will be redirected to Feedburner for everyone except FeedValidator and of course Feedburner itself. To add additional exceptions to the redirect, simply replicate either line containing RewriteCond, and edit the user agent (e.g., FeedBurner) to suit your needs. Of course, if you plan on using both of these redirects (i.e., all content and comment feeds), continue reading for a better technique..
New and Improved Method for Redirecting WordPress Feeds to Feedburner
For those of us using Feedburner for all content and comment feeds, we have consolidated the previous htaccess code into a single redirect. Additionally, we improve functionality by verifying the requested URI and simplifying the regex used to match the target string. Check it out:
# temp redirect all wordpress feeds to feedburner
<IfModule mod_rewrite.c>
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]
</IfModule>
If you are redirecting both content and comment feeds, this “new and improved” htaccess code will do the job nicely. With optimized code and improved functionality, it is definitely recommended over the previous directives. Simply edit the URLs in the last two lines to match your own Feedburner addresses (one for posts and the other for comments), and place the code into your blog’s root htaccess file. No other changes should be required. Once the code is in place, test that everything is working by accessing your feed directly using its default (i.e., non-redirected) URL. After that, you can sit back, relax, and enjoy all the benefits of WordPress, Feedburner, and one less plugin to worry about.
<update> (12/15/2008) If either of your feeds will not redirect using the “new and improved” redirect code, try commenting out the following line:
RewriteCond %{REQUEST_URI} ^/?(feed.*|comments.*) [NC]
..and that should do the trick. Or, another option is to use the two “original” redirects provided in the beginning of this article. </update>
61 Responses
Simon – February 8, 2009
Hi Jeff, same here! It seems your blog always holds the answers to some of my questions :)
Thanks for the fast response. I think I tried everything but it never redirects anything. I just put it in the httaccess right? Maybe below # END WordPress or fo i put it in there?
Cheers Simon
Jeff Starr – February 8, 2009
@Simon: Before the WordPress permalink rules! And, be sure that you try this method as well:
<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]RewriteRule ^feed/?.*$ http://feeds.feedburner.com/yourfeed [L,NC,R=302]</IfModule>If that doesn’t work, there may be something else that is interfering..
Simon – February 8, 2009
Juhui (swiss exclamation of joy)! Works like a charm. One less plugin in my neverending list. You’re a genious the last one workes perfectly. :)
Jeff Starr – February 8, 2009
Excellent! Happy to help, Simon! :)
Justin Tadlock – June 17, 2009
Jeff, I hope you don’t mind me troubling you for a moment, but this is far from my area of expertise. Your first set of code above works great for me. It always has.
I have one feed in particular that I need to exclude from being redirected (
http://justintadlock.com/feed/wordpress-o-sphere), which is a custom-created feed. I don’t need it redirected at all, but I’d like to redirect everything else.The rewrite rule currently is:
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds2.feedburner.com/JustinTadlock [R=302,NC,L]I usually figure these things out pretty quickly, but I’m stuck on this one. If you have a moment and know how to do this, I’d appreciate it if you’d lend a hand. I’ve got a tutorial coming up on creating custom feeds, but I can’t show off the feed because it’s being redirected to Feedburner.
Jeff Starr – June 20, 2009
Sorry for the delay on this – had my wisdom teeth out and things got quite hectic..
That is tricky one for sure, but a few things come to mind that might be of some help..
1) If at possible, use a different directory for the custom feed. Your current rewrite rule would then skip the custom-feed directory, enabling you to simply create a new rule for it.
2) Depending on how many feeds you have at your site, exchange the wild-card pattern-matching for a specifically targeted list of feeds (e.g., any feed that actually goes to Feedburner). As with the first option, this would enable you to target as many custom feeds as needed.
3) In general, rewrite directives for excluding requests for specific patterns that are included subsequent conditions is difficult. You may have luck using mod_rewrite for the general pattern-matching directives and then mod_alias for the exclusive case (i.e., for the custom feed).
I hope that proves useful – let me know if I may be of any further assistance.
Justin Tadlock – June 20, 2009
Thanks. I don’t know why I just didn’t think to change the name of the custom feed directory. That makes things super easy. Sometimes, it just takes a fresh set of eyes to find the simplest things.
Jeff Starr – June 20, 2009
Anytime, Justin! Your articles have helped me on many occasions — more than happy to return the favor :)
Agus Suhanto – September 12, 2009
Thanks for the .htaccess code.
I just wondering why we don’t use the following rewrite rule for the comments feed:
RewriteRule ^comments/feed/?.*$ http://feeds.feedburner.com/comments-feed [L,NC,R=302]because if I use
^comments/?.*$, it will also match the url:http://domain.tld/comments-feedwhich I suppose should be use by a WP page?
Looking forward for your response.
regards,
Agus Suhanto
Jeff Starr – September 13, 2009
Hi Agus, yes you should include the extra match information to keep the rules targeted on your feed page only. It is a good idea, but test like crazy to make sure everything is working as expected.
Regan Frank – November 12, 2009
Hi,
Just wanted to say thanks for this hack. I really needed something to work for me and your code was a god send. Thanks
Gregory Foster – November 30, 2009
Hi Jeff, thank you for the useful post, this is exactly what I was looking for.
I ran into one thing I had to change to get this to work on my server (Apache 2.2.3), and I wanted to bring it up because I wonder if you or others have run into it. It has to do with whether the
REQUEST_URIincludes a leading slash. In my setup, theREQUEST_URIs do come in with the leading slash. In your code, you add a conditional check for the presence of a leading slash in your firstRewriteCond, but then that check is absent in theRewriteRule– this is what caused the rule to be skipped in my server configuration. Do the grouping parentheses you include parse that out for subsequent checks?Here’s what I settled on (only for main feed):
# FeedBurner support.RewriteCond %{REQUEST_URI} ^/feed.* [NC]RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]RewriteRule ^/feed.* http://feeds.feedburner.com/entersection [L,NC,R=302]Thank you, and btw your blog’s design is really beautiful. Makes me think you must live in the southwest U.S. somewhere :)
gf