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

WordPress Feedburner HTAccess Redirect for Default (Non-Permalink) Feed URLs

Recently, a client wanted to deliver her blog feed through Feedburner to take advantage of its excellent statistical features. Establishing a Feedburner-delivered feed requires three things: a valid feed URL, a Feedburner account, and a redirect method. For permalink-enabled WordPress feed URLs, configuring the required redirect is straightforward: either install the Feedburner Feedsmith plugin or use an optimized HTAccess technique. Unfortunately, for sites without permalinks enabled, the Feedsmith plugin is effectively useless, and virtually all of the HTAccess methods currently available on the Web are designed for permalink-enabled configurations. In this article, we will modify our existing HTAccess technique to work with default WordPress feed URLs.

Default WordPress Feed Format

By default, WordPress feed URLs look similar to the following:

Main Feed:
http://domain.tld/blog/?feed=rss
http://domain.tld/blog/?feed=rss2
http://domain.tld/blog/?feed=atom

Comment Feed:
http://domain.tld/blog/?feed=comments-rss2

..depending on your preferred WordPress feed URL. These default (non-permalink) feed URLs employ query-string parameters to specify the type and format of each feed. Unfortunately, these dynamic URL formats do not work with Feedburner’s own Feedsmith redirect plugin. Fortunately, we can skip using a plugin altogether and use a little HTAccess magic instead.

HTAccess Redirect for Permalink-Enabled WordPress Feeds

Let’s review the code required to redirect all permalink-formatted WP feeds:

# TEMP WORDPRESS FEEDBURNER REDIRECT for PERMALINKS
<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/yourfeedname [L,NC,R=302]
</IfModule>

..which works great for redirecting your permalink feeds to your Feedburner feed. To accomplish this, the RewriteCond matches the “feed” or “comments” pattern in the requested URI. The RewriteRule then redirects all matched URLs to the established Feedburner feed. So, to get this HTAccess method to work with default (i.e., dynamic) WordPress feed formats, we need to modify the RewriteCond to match against the QUERY_STRING rather than the REQUEST_URI.

HTAccess Redirect for Default WordPress Feeds

For WordPress sites without permalinks enabled, we must modify our rewrite rules to recognize feed parameters located in the query string of requested URLs. The resulting HTAccess code for redirecting all default (non-permalink/dynamic) WordPress feeds to Feedburner looks like this:

# PERISHABLE PRESS FEEDBURNER REDIRECT for DEFAULT WORDPRESS FEEDS
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTP_USER_AGENT} !^.*(feedburner|feedvalidator)                        [NC]
 RewriteCond %{QUERY_STRING}     feed=(rss|rss2|atom).*                               [NC]
 RewriteRule ^(.*)$              http://feeds.feedburner.com/ContentFeed?             [NC,R=302]
 RewriteCond %{QUERY_STRING}     feed=(comments\-rss|comments\-rss2|comments\-atom).* [NC]
 RewriteRule ^(.*)$              http://feeds.feedburner.com/CommentFeed?             [L,NC,R=302]
</IfModule>

When placed in your site’s root HTAccess file (or Apache config file), this code will redirect all requests for your default WordPress feeds to your specified Feedburner feed. Simply edit the “ContentFeed” and “CommentFeed” portion of the RewriteRule to match the corresponding Feedburner URLs. No other editing is required. This code will match and redirect all requests (unless from FeedBurner or FeedValidator) for both your main content and comment feeds in any format. As expected, category, archive, and individual comment feeds are not affected by this code. This method is more comprehensive than the Feedsmith plugin, but not so aggresive as to redirect your peripheral feeds (i.e., any feeds other than your main content and main comment feeds).

Breakdown

Before applying new code, it’s always smart to understand its functionality, especially when it comes to HTAccess. Fortunately, this redirect method is fairly straightforward, matching various regex patterns and redirecting them to their new location. As a precautionary measure, the entire method is enclosed within an IfModule container to check that the required Apache module (in this case, mod_rewrite) is available before executing the enclosed directives.

Within this container, the first step is to enable the RewriteEngine. If the RewriteEngine has already been enabled, this directive may be omitted. The remaining four lines of this method accomplish the matching of the desired feed URLs and their subsequent redirection to the specified Feedburner feeds. To do this, first RewriteCond directive checks that the user agent is neither feedburner nor feedvalidator (case-insensitive match courtesy of the [NC] flag). The two subsequent RewriteCond directives then match any instances of the default feed parameters (e.g., atom, rss, rss2) in the QUERY_STRING of the requested URL.

Finally, any URLs that are matched by the RewriteConditions are rewritten to their specified Feedburner URL. As this temporary redirect occurs, the query string is removed from the rewritten URL via the question mark appearing near the end of each RewriteRule.

Of course, that is merely an overview of the process; there is of course much more happening both logically and functionally, but this article is getting long enough as it is, and I certainly wouldn’t want to bore you with all of the in-depth technical details. Perhaps I will dig into the deeper mechanics of such methods in a future article..

Redirect Only the Main Feed

For the record, here is the code required to redirect only the main RSS2 feed to Feedburner:

# PERISHABLE PRESS FEEDBURNER REDIRECT for the DEFAULT WORDPRESS RSS2 FEED
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{QUERY_STRING}     feed=rss2                                [NC]
 RewriteCond %{HTTP_USER_AGENT} !^.*(feedburner|feedvalidator)            [NC] 
 RewriteRule ^(.*)$              http://feeds.feedburner.com/ContentFeed? [L,NC,R=302]
</IfModule>

As before, the only edit that needs to be made is to change the “ContentFeed” portion of the RewriteRule to match the URL of the target Feedburner feed. Once in place, this method will redirect all requests (except for those from Feedburner and FeedValidator) for your main feed to the specified Feedburner URL. Customize as needed to suit your specific needs.

Later Daze

If you need to redirect the default, non-permalink versions of your WordPress feed URLs to their associated Feedburner accounts, the HTAccess techniques presented in this article will do the job nicely. 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.

About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
The Tao of WordPress: Master the art of WordPress.

18 responses to “WordPress Feedburner HTAccess Redirect for Default (Non-Permalink) Feed URLs”

  1. Christopher Ross 2008/10/13 10:47 am

    .htaccess based redirects are wonderful. I’m always baffled by web professionals who don’t take the time to learn more about them.

  2. WWW Redirect 2008/10/17 2:52 am

    I always think server level redirection is better than code-level (such as with a plugin) because if the server doesn’t have to load PHP at all. It is much faster.

    The problem is, of course, people don’t always have access to configuration files, or in this case, .htaccess — or they don’t know how to edit one.

    –Hendry

  3. Jeff Starr 2008/10/19 2:44 pm

    @Christopher: So true! My traffic would certainly increase if more web professionals would strive to learn about the amazing things possible with htaccess! ;)

    @Hendry: I always tell people that if their host doesn’t provide per-directory htaccess support, it’s time to switch hosts! :)

  4. Great info, but how do you get feedburner to recognize the new feed? When trying to edit the details of my feed at feedburner, I always get an error or a “Bang Kapow Krackkk” error from Feedburner when trying to access it. http://feeds.feedburner.com/peanutbutterboy

  5. @Nick: What is the feed URL you are using as the source feed for your FeedBurner account?

  6. Right now it’s set to http://www.peanutbutterboy.com/?feed=atom which isn’t working, but I’ve tried /feed, /feed/, /?feed=rss2, and every combination I can think of, but Feedburner rejects every single one saying “Connection Reset”. I am using Permalink with rewrite rules for /year/month/post-title, I have tried it with and without your htaccess modifications but Feedburner still can’t set the original feed correctly.

  7. It is not unusual to experience difficulties getting FeedBurner to recognize your feed(s). A couple of things to try (if you haven’t done so already):

    1. Verify that your feed(s) are valid (or close to it)
    2. Check your feed with other services and aggregators
    3. Try creating a new FeedBurner account and starting fresh
    4. Try testing your FeedBurner account with a feed that is recognized and working (e.g., you could use my feed URL momentarily to see if there is a problem with your FeedBurner account)

    Hopefully, some of these tests will provide more information as to the source of the issue. It could be your server, your WordPress installation, one of your plugins, or the FeedBurner account itself.

  8. I’ve tried all of the above. You’re feed burns fine in the old and new account but I can’t get mine to burn on either. But now I’m hearing that some people can’t even access my site? maybe a WP plugin? Hosting/DNS settings?

  9. But Feedblitz can read the feed fine, so can Firefox and Google’s RSS feed reader….

  10. Jeff Starr 2008/10/21 4:29 pm

    Hmmm.. interesting. Something is definitely interfering. It sounds as if the FeedBurner account is working fine, and your feed seems to be formatted properly (and working elsewhere).. Another thing you could try (if you haven’t already), would be to try using other feeds available from your site. For example, check if your comment feed works, or perhaps some different tag and archive feeds.. That would at least provide information about whether the issue is with your main feed(s) or else with the WordPress installation in general. Then again, if people are having difficulties accessing your site, you may be dealing with a much larger issue. And, one other thing you could try that may take a bit of time, is to install a fresh installation of WordPress somewhere else on the same server and testing if its feed works. If not, I would guess that the problem involves some server setting(s). I hope that helps!

  11. Jeff Starr 2008/10/21 5:07 pm

    Are there any other htaccess rules that might be interfering with feed access?

  12. What’s interesting is that the first post I created on the newly hosted site was distributed fine, meaning that the feed must have still been readable by Feedburner but as of 2 days ago that has changed. I tried the comments feed and also two old .xml feeds that I uploaded to my site, http://www.peanutbutterboy.com/rss.xml and atom.xml. Both of those are valid feeds but Feedburner can’t recognize them either. I also think Stumbleupon.com is having trouble accessing my site…something’s wrong for sure, but all my serving settings are default and normal.

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 »
WP Themes In Depth: Build and sell awesome WordPress themes.
Thoughts
I disabled AI in Google search results. It was making me lazy.
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. Also: “The Web” is not a valid answer.
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
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.