Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

Redirect WordPress Feeds to Feedburner via htaccess (Redux)

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-]+)?/?$ https://feeds.feedburner.com/yourfeedname [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-]+)?/?$ https://feeds.feedburner.com/yourfeednamecomments [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 “https://feeds.feedburner.com/yourfeedname” and/or “https://feeds.feedburner.com/yourfeednamecomments” to match your own address. With this htaccess code in place, your feeds will be redirected to Feedburner for everyone except FeedValidator (or whichever feed-validation service you are using, edit code to match its user agent) 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/?.*$          https://feeds.feedburner.com/yourfeedname         [L,NC,R=302]
 RewriteRule ^comments/?.*$      https://feeds.feedburner.com/yourfeednamecomments [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

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>

About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
WP Themes In Depth: Build and sell awesome WordPress themes.

61 responses to “Redirect WordPress Feeds to Feedburner via htaccess (Redux)”

  1. Jeff Starr 2009/02/08 1:09 pm

    @Patrix: Unfortunately, we can’t use HTAccess to control whether or not a feed is full or partial, however, I do recall seeing a plugin called “Feed Control” (or something similar) that provides granular control over the formatting of your various feeds. If you can’t find a plugin or function to do the job, you may want to try experimenting with Yahoo! Pipes, which is a feed aggregator that enables the creation of custom feeds, formatting, and so on.

    @Simon: Great to see you again! The technique described in the article should do exactly what you need. Make sure you read the update note at the end of the post if you are experiencing any issues.

  2. Jeff Starr 2009/02/08 1:52 pm

    @Simon: Before the WordPress permalink rules! And, be sure that you try this method as well:

    <IfModule mod_rewrite.c>
       RewriteEngine on
       RewriteCond %{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..

  3. 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. :)

  4. Jeff Starr 2009/02/08 4:44 pm

    Excellent! Happy to help, Simon! :)

  5. Justin Tadlock 2009/06/17 7:50 pm

    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.

  6. Justin Tadlock 2009/06/20 7:28 am

    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.

  7. Jeff Starr 2009/06/20 6:54 am

    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.

  8. Jeff Starr 2009/06/20 7:32 am

    Anytime, Justin! Your articles have helped me on many occasions — more than happy to return the favor :)

  9. Agus Suhanto 2009/09/12 8:35 pm

    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-feed

    which I suppose should be use by a WP page?

    Looking forward for your response.

    regards,
    Agus Suhanto

  10. Jeff Starr 2009/09/13 8:27 am

    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.

  11. Regan Frank 2009/11/12 11:25 pm

    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

  12. Gregory Foster 2009/11/30 9:50 pm

    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_URI includes a leading slash. In my setup, the REQUEST_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 first RewriteCond, but then that check is absent in the RewriteRule – 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

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Digging Into WordPress: Take your WordPress skills to the next level.
Thoughts
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Crazy that we’re almost halfway thru 2024.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.