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 RewriteCond
itions 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.
18 responses to “WordPress Feedburner HTAccess Redirect for Default (Non-Permalink) Feed URLs”
.htaccess based redirects are wonderful. I’m always baffled by web professionals who don’t take the time to learn more about them.
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
@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! :)
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
@Nick: What is the feed URL you are using as the source feed for your FeedBurner account?
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.
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):
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.
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?
But Feedblitz can read the feed fine, so can Firefox and Google’s RSS feed reader….
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!
Are there any other htaccess rules that might be interfering with feed access?
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.