Redirect WordPress Individual Category Feeds to Feedburner via HTAccess

Post #647 categorized as WordPress, last updated on Dec 15, 2008
Tagged with feedburner, feeds, htaccess, plugins, redirect, WordPress

Time for another Feedburner redirect tutorial! In our previous FeedBurner-redirect post, I provide an improved HTAccess method for redirecting your site’s main feed and comment feed to their respective Feedburner URLs. In this tutorial, we are redirecting individual WordPress category feeds to their respective FeedBurner URLs. We will also look at the complete code required to redirect all of the above: the main feed, comments feed, and of course any number of individual category feeds. Let’s jump into it..

Initial Setup

As we are redirecting our category feeds to their associated FeedBurner URLs, you will first want to make sure that these feeds exist and are accessible. Once you have the URLs of the FeedBurner feeds for your categories, make a list of their associated WordPress categories for easy reference. In addition to this information, you will need:

  • A WordPress-powered blog (with the required categories)
  • An Apache server with the mod_rewrite module enabled
  • Access to to your domain’s root HTAccess file (or to httpd.conf)

For this tutorial, we will assume the following hypothetical WordPress/Feedburner feed URLs:

  • Main feed:
    http://domain.tld/feed/
    == http://feeds.feedburner.com/main-feed
  • Comments feed:
    http://domain.tld/comments/feed/
    == http://feeds.feedburner.com/comments-feed
  • “Business” category feed:
    http://domain.tld/category/business/feed/
    == http://feeds.feedburner.com/business-feed
  • “Pleasure” category feed:
    http://domain.tld/category/pleasure/feed/
    == http://feeds.feedburner.com/pleasure-feed
  • “Nonsense” category feed:
    http://domain.tld/category/nonsense/feed/
    == http://feeds.feedburner.com/nonsense-feed

Redirecting Category Feeds

Here is the generalized HTAccess code that we will be using to redirect our three categories:

# Redirect Wordpress Category Feeds to Feedburner
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
 RewriteRule ^category/business/feed/?.*$ http://feeds.feedburner.com/business-feed [L,NC,R=302]
 RewriteRule ^category/pleasure/feed/?.*$ http://feeds.feedburner.com/pleasure-feed [L,NC,R=302]
 RewriteRule ^category/nonsense/feed/?.*$ http://feeds.feedburner.com/nonsense-feed [L,NC,R=302]
</IfModule>

That’s the core of this tutorial, right there. The first line checks for the existence of the required Apache module, mod_rewrite, while the second line enables the module (you may remove this line if already included in your file). Then, the third line ensures that the two Feedburner user agents are not redirected. The next three lines each match against a specific category feed URL and subsequently redirect the request to the appropriate Feedburner counterpart. Further, we are using the “No-Case” ( [NC] ) modifier to ensure case-insensitive pattern matching for all directives. Finally, each of the three rewrites is executed as a “Temporary” ( [R=302] ) redirect.

Now, to implement this method, edit the last three lines according to your specific category and Feedburner feed information. Double-check that the changes are accurate. For additional categories, duplicate one of the three RewriteRules and edit as necessary. For fewer categories, simply delete one or two of the last three lines and edit as necessary. Once you have edited the code to meet your needs, place the entire chunk of code into your site’s root HTAccess file. If your WordPress installation is located in a subdirectory, you may also place the code in the root HTAccess for that subdirectory. In either case, make sure that this code is placed before the default WordPress permalink rules. Once uploaded to your server, verify functionality by navigating to your redirected category feeds. If everything is place and edited correctly, the redirects should be working and your category feed URLs should be opening their associated Feedburner feeds.

Redirecting Main, Comments, and Category Feeds

Chances are, if you are redirecting your WordPress category feeds to Feedburner, you will also want to redirect your blog’s main feed and comments feed as well. With our category-redirect code in place, we simply need to add two additional lines of code:

RewriteRule ^feed/?.*$     http://feeds.feedburner.com/main-feed     [L,NC,R=302]
RewriteRule ^comments/?.*$ http://feeds.feedburner.com/comments-feed [L,NC,R=302]

Edit these two lines of code with your particular feed information and then place them into the category-redirect code as follows:

# Redirect Wordpress Category Feeds to Feedburner
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
 RewriteRule ^feed/?.*$     http://feeds.feedburner.com/main-feed     [L,NC,R=302]
 RewriteRule ^comments/?.*$ http://feeds.feedburner.com/comments-feed [L,NC,R=302]
 RewriteRule ^category/business/feed/?.*$ http://feeds.feedburner.com/business-feed [L,NC,R=302]
 RewriteRule ^category/pleasure/feed/?.*$ http://feeds.feedburner.com/pleasure-feed [L,NC,R=302]
 RewriteRule ^category/nonsense/feed/?.*$ http://feeds.feedburner.com/nonsense-feed [L,NC,R=302]
</IfModule>

With that code in place (and properly edited), your server will redirect all requests for your blog’s main, comments, and specified category feeds to their respectively associated Feedburner feed URLs. All other types of feeds (tags, post comments, author feeds, etc.) will not be affected and will appear as normal when requested.

Props

Thanks to Alexander for his question about redirecting category feeds. His code was used as the catalyst for the elaborated techniques presented in this article.

Subscribe to Perishable Press


34 Responses

TopLeave a comment

[ Gravatar Icon ]

#1Alexander

Glad I was able to help, thanks for the mention too. :)

[ Gravatar Icon ]

#2shalako

Thanks for this; been looking for a method as all the plugins I have tried are unreliable.

However, I found that after implementing the method it broke my feedburner feeds. What am I doing wrong?

There was a problem retrieving the feed: com.burningdoor.rsspp.resource.impl.HttpConnectionException: Error getting URL: 400 - Recursive feed redirection error: Are requests for your ‘Original Feed’ address — the feed that FeedBurner is checking for updates — being redirected to your FeedBurner feed? Make sure your Original Feed is provided from a web address that isn’t redirected to FeedBurner.

[ Gravatar Icon ]

#3Web Design Sussex

Thankyou for this article, I finally got my feeds redirecting. I had some major hasslestrying to enable mod_rewrite on my server but got there eventually. Happy new year.

[ Gravatar Icon ]

#4Brass Engraved

Thankyou very much for this, worked like a dream!

[ Gravatar Icon ]

#5Friedbeef

I had trouble getting Feedsmith to work - thanks so much for posting this up! works perfectly (once I remembered to put the code BEFORE my permalinks code :)) Brilliant stuff!

[ Gravatar Icon ]

#6Josh

First of all congratulation for such a great site. I learned a lot reading here today. I will make sure i visit this site more often so i can learn more.

[ Gravatar Icon ]

#7UK Web Designer Directory

Thanks for this writeup, your method worked almost perfectly except a few modifications to htaccess were required.

[ Gravatar Icon ]

#8Jeff Starr

@UK Web Designer Directory: My pleasure for the writeup. Glad it is useful for you. Btw, it would be great to hear about the “required” htaccess modifications that you used, especially if they apply to the code in general.
Thanks,
Jeff

[ Gravatar Icon ]

#9Mo

Thanks for this article. But is a 302 really the best way or practical?

[ Gravatar Icon ]

#10Jeff Starr

@Mo: Good question. I have read arguments supporting both 302 (temp redirect) and 301 (permanent redirect). The crux of the argument rests on the fact that Feedburner is a service that processes feeds from an original source. If/when Feedburner ever stops providing the service (and even if they don’t), the feeds will still belong to their respective sources, and thus it is argued that the redirect is in fact “temporary” in nature.

What are your thoughts on the subject?

[ Gravatar Icon ]

#11Harsha

thanx for the tutorial.. when i try to add feeds of the category in the feed burner i am getting the following error

Your feed filesize is larger than 512K. You need to reduce its size in order for FeedBurner to process it. Tips for controlling feed file size with Blogger can be found in Tech Tips on FeedBurner Forums, our support site.

[ Gravatar Icon ]

#12Jeff Starr

@Harsha: First, double-check and verify that your feed size is over the limits. Second, how many posts are you delivering via your feed? 512K corresponds to a huge file. If Google is choking on it, chances are other (smaller) services are as well.

[ Gravatar Icon ]

#13Harsha

@Jeff

The funny part is the main feed is valid not the category one. And worst part is i have a max of 5 posts in that category.

[ Gravatar Icon ]

#14david

Did not work for me whatsoever, in fact it broke my main feed redirect using feedsmith. Went back to original htaccess and had to deactivate then reactivate the feedsmith plugin to get the redirect working again. Could the plugin have caused a conflict so this failed? Deleted feedsmith plugin, somehow my main feed is still redirecting to feedburner and I have no idea how! htaccess has no feed redirects, no feedsmith plugin, but it still redirects, is the redirect cached somewhere? Guess I’ll wait to see if it eventually stops redirecting, then I’ll try to update htaccess again.

[ Gravatar Icon ]

#15david

got all of them working except for one now, no end of tinkering. i suspect i had issues because i starting changing the feedburner url’s before putting in the redirect rules, and possibly feedburner hadn’t updated yet, so when it tried to grab the original feed it got a redirect or something, i’d recommend not doing this. in the end i deleted feedsmith plugin, started with a fresh htaccess, and now like i said, all feeds are redirecting appropriately except for one category feed. i’ve check it many times and the code is correct, no idea why this one refuses to redirect. hopefully it’s a caching issue and will resolve itself, will post again.

[ Gravatar Icon ]

#16david

finally working for everything! removed all redirection, resynced feedburner, waited 10 minutes, put redirection back into htaccess, works fine now. thanks for the post!!

[ Gravatar Icon ]

#17Jeff Starr

Hi David, wow that’s quite the drama! Thanks for following up with the solution — glad to hear you got it working :)

[ Gravatar Icon ]

#18david

Had to come back and post again, I realized that when I implement these rules my feedburner feeds stop updating. My best guess is that when feedburner requests the original xml, it is forwarded to the feedburner feed, and so there is a loop created. I’m guessing this code is intended to tell the feedburner service not to follow the redirect?

RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]

But perhaps it’s not working for me for some reason? It would explain the difficulties I had at the beginning as well. But could there be some other reason for this not working? I can’t think of anything else.

Here’s an example of my htaccess, please let me know if you see anything wrong. Thank you!!!

# BEGIN WordPress
# Redirect Wordpress Category Feeds to Feedburner
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
   RewriteRule ^feed/?.*$ http://feeds.feedburner.com/feedname [L,NC,R=302]
   RewriteRule ^category/category-name/feed/?.*$ http://feeds.feedburner.com/feed-name [L,NC,R=302]

   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.php [L]
</IfModule>
# END WordPress

[ Gravatar Icon ]

#19david

dont bother with what i went through :)

use this plugin
http://wordpress.org/extend/plugins/feedburner-plugin/

it can redirect category feed automatically.

cheers!

[ Gravatar Icon ]

#20Jeff Starr

Hi david,

Not sure what the issue might be, I have tested this code and used it myself on a number of occasions. One thing that may be causing some trouble is the way in which you have placed the FeedBurner directives inside the WordPress permalink container. Newer versions of WordPress auto-detect the presence of a specific sequence of permalink directives, and if no match is found, it rewrites/re-includes them. So things may be getting overwritten/modified on the server without the user actually being aware (kinda bad, really).

Other than that, not sure. Others seem to have used the code successfully, but if a plugin works for you, then by all means go with it.

Btw, I didn’t think that there were any FeedBurner plugins that actually handled the category-specific redirects.. Are all of your feeds pointed to the same FeedBurner URL?

[ Gravatar Icon ]

#21david

not exactly sure i understand what the permalink issue would be, but the plugin has the option of redirecting all categories to one url, or of appending category name to the url, so like FEEDBURNERURL_categoryname which allows you to create category feeds automatically

[ Gravatar Icon ]

#22Jeff Starr

Yes, nice - I just downloaded and checked out a copy for myself. Looks like just the ticket for handling individual tag and category feeds, something that wasn’t possible with a plugin back when I wrote this article. Thanks for sharing your solution - good to know.

[ Gravatar Icon ]

#23Mobile tracker

Great, I have been learning how to use .htaccess and regular expression for sometime now, thanks for the example, really helpfull.

[ Gravatar Icon ]

#24Satya Prakash

Same with me. I am getting recursive redirection error

[ Gravatar Icon ]

#25Juana

Hi Jeff -

Thanks for your post. It worked. I do have q: Bloglines is still showing the feed as empty although feedburner has all of my posts. Would you know how I can fix that? I have to be doing something wrong. I emailed Bloglines but so far 3 biz days and no answer. Argh!

Thanks in advance!

Juana

[ Gravatar Icon ]

#26Satya Prakash

These all are proved to be a waste of time. You can read my post here: http://www.satya-weblog.com/2010/02/redirect-wordpress-feed-url-feedburner.html.
Better to just use feedsmith plugin and use the technique similar to I have used. and mentioned in the post for which link given.

[ Gravatar Icon ]

#27Jeff Starr

@Juana: unfortunately, no, I don’t have any ideas for the bloglines stuff. Hopefully they will respond with some help.

@Satya Prakash: thanks for the information. I will check it out and test as soon as I get the time. Remember to put the code before your permalink directives (if you haven’t tried that already).

[ Gravatar Icon ]

#28Nick M

Thank you so much for this! It cured a huge panic-induced headache! And thanks for specifying that the redirect code has to go BEFORE the default Wordpress permalink rules. This is vital, as it doesn’t work when the redirect code is placed after permalink rules.

Share your thoughts..

TopRead official comment policy

The rules are simple. Comment intelligently. Stay on-topic. Don’t spam! Suspected spam will be deleted. Use your real name or nickname, not a site name or business name. Using a site name or business name is a good way to get your link or comment removed. Certain comments are moderated; if your comment does not appear after several days, or if you wish to comment privately, contact me. Also, by posting a comment, you grant this site a perpetual license to reproduce your comment, name, and website URL. Lastly, you may use basic HTML markup, but please do not use <pre> tags. Instead, wrap your code with <code> tags. Use a new set of <code> tags for each code term or phrase, as well as for each individual line of code (i.e., multiple lines of code require multiple code tags). Please see the complete comment policy for more information.