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

Published Monday, October 13, 2008 @ 8:03 am • 14 Responses

[ ~{*}~ ] 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 WordPress 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/?.*$          http://feeds.feedburner.com/perishablepress         [L,NC,R=302]
 RewriteRule ^comments/?.*$      http://feeds.feedburner.com/perishablepresscomments [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 (in case-insensitive [NC] fashion). 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 assigned Feedburner URL.

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.


Dialogue

14 Responses Jump to comment form

1Christopher Ross

October 13, 2008 at 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.

2WWW Redirect

October 17, 2008 at 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

3Jeff Starr

October 19, 2008 at 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! :)

4Nick

October 20, 2008 at 4:14 pm

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

5Jeff Starr

October 21, 2008 at 10:41 am

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

6Nick

October 21, 2008 at 10:46 am

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.

7Jeff Starr

October 21, 2008 at 11:14 am

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.

8Nick

October 21, 2008 at 12:57 pm

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?

9Nick

October 21, 2008 at 1:02 pm

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

10Jeff Starr

October 21, 2008 at 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!

11Nick

October 21, 2008 at 4:50 pm

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.

12Nick

October 21, 2008 at 4:54 pm

Btw, I also have a wordpress installation at http://www.peanutbutterboy.com/test/ and none of those rss feeds are working either.

13Jeff Starr

October 21, 2008 at 5:07 pm

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

14Nick

October 21, 2008 at 5:32 pm

No, that’s what I thought at first, but I’ve only got the WP Permalink htaccess rules:

# BEGIN WordPress

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Although I add both of the “Options” lines in an attempt to troubleshoot, but it doesn’t seem to work either way!

Subscribe to comments on this post


Share your thoughts..

TopRead official comment policy

Contact Perishable Press

  • Contact Jeff via form

Search Perishable Press

About Perishable Press

Perishable Press is the virtual playground of Jeff Starr — visionary, founder and lead developer of Monzilla Media, a small web and graphic design company in the lush desert oasis of Moses Lake, Washington. Perishable Press features articles and tutorials on many aspects of digital design..

Read more..

Perishable on Twitter

better to have too many ideas and not enough time than the converse

Perishable on Tumblr

WordPress Tip for Multiple Themes

Sunday, 4 January 2009, 5:16 pm

If your site makes available multiple themes for users to choose from, remember to include the JavaScript (or any other required code) for any statistical applications that you might be using, such as Mint, Google Analytics, and so forth. I am not sure about the various WordPress statistics plugins, but they may need to be included as well. A good way to check if your stats plugin is tracking data across all themes is to either visit a few pages that you know others aren’t hitting, or else activate each of the alternate themes and check the source code of each one for the required code.

Earlier today, I realized that only several of my most recent themes included the required JavaScript for Mint and Google Analytics. I am now in the process of editing each of the 18 themes available for users at Perishable Press. Haven’t decided on whether or not both statistics apps are needed for all themes, but I will certainly be using at least one of them to keep an eye on everything.

Insane Christmas

Monday, 22 December 2008, 9:47 pm

For as long as I can remember, Christmas has always been a relatively peaceful affair. Sure there’s the usual holiday stress — traffic, shopping, presents, relatives, and all that goes with the preparation of a traditional celebration, but when it’s all said and done, you get to relax and enjoy the peace and harmony of gathering together and basking in the reason for the season: the birth of Christ.

This year, however, the stress factor has been kicked up a few notches, making for a rather insane Christmas if I do say so myself. In addition to the usual holiday chaos, we are currently purchasing a brand new home, and quickly realizing the incredible amount of work involved in the process. If you’ve ever bought a newly built home, you know exactly what I am talking about here.

Plus, as if all the paperwork, inspections, insurance, costs, and anxious anticipation weren’t enough to confound the usual holiday stress, we are also packing up everything, dealing with kids, working full-time jobs, and — beginning on Christmas Eve — moving into our new house.

It certainly is all a great joy and blessing to have such amazing things going on, but combined with the work that I do on the Web — blogging, designing, projects, helping people, and so on — it really becomes all too much rather quickly. We are doing are best to get through everything with our sanity intact, but I have to admit that this is the most insane Christmas I have ever experienced.

New (4G) Blacklist Now in Beta

Monday, 22 December 2008, 9:27 pm

Just a quick note to anyone interested in securing their websites against malicious activity, spam, and other nonsense. Several months after releasing my 3G Blacklist, I have finally begun work on the next incarnation of the blacklist: the 4G Firewall!

The first part of the blacklist is now ready for testing, and I plan on setting it up on Perishable Press within the next few days. While testing on my own site, I thought it would beneficial to also invite a few “beta” testers to run the code on their own site(s) as well.

So, if you have a site that receives its share of malicious attacks, and cracker exploits, drop me a line via the contact form at Perishable Press and I will send you the initial block of HTAccess directives. This version of the Blacklist is looking better than ever, and I look forward to releasing the complete version to the public early in 2009.

Thanks for the Free Traffic and Link Juice

Sunday, 7 December 2008, 1:26 pm

Just wanted to thank the fine folks at fafich.ufmg.br for all the free traffic and link juice. Thanks to their misapplication of my comprehensive canonicalization code, every non-canonical version of their 21,700 indexed pages points directly to my site, Perishable Press. This means that every one of their permalink URLs that is mistyped, lacks the “www” prefix, or contains the superfluous “index.php” file name is directed via permanent redirect directly to the home page of my site.

I have tried contacting the site owner(s) about this situation, but it has been over a week and I have yet to hear anything back. Hopefully, they will take notice soon and correct the issue by properly configuring their htaccess file, but in the meantime, I certainly don’t mind the extra link juice and free traffic! :)

No Plugin Needed for Feed Delay

Monday, 24 November 2008, 10:01 am

I recently saw a WordPress plugin that was designed to delay the publication of your WordPress feed by any specified time interval. While it is a good idea to carefully proofread your content before posting it, a plugin certainly is not required to do so.

As savvy WordPress users already know, WordPress has a built-in post-preview feature that enables authors to view their unpublished content as a published post. This enables authors to do any amount of proofreading and browser checking until they are satisfied with the results.

To do this, simply write your post as usual, and then click on the “Preview this post” button on the right-hand side of the screen. In older versions of WordPress (less than 2.5, I think), you actually need to save (without publishing!) the post first and then re-open it as if to continue editing. You will then see a “Preview »” link sort of hidden (due to poor CSS design) in the upper-right corner near the edit post field. Right-click on that link to open in new tab and you are good to go.

No extra plugin needed! :)

Read more on Tumblr..

Subscribe to Comments Recent Dialogue

  • Jeff Starr: Hi heywho, glad to hear you are doing well! ;) I wish I could join in the festivities.. it has been so long that I almost have forgot...
  • Rob Barrett: Thanks for posting about the Stealth Publish plugin -- just what I needed for my site. Works perfectly!...
  • Jeff Starr: Hi Chiwan, I got your email and have sent some information that may help you with this. Cheers, Jeff...
  • Chiwan: Hi. This is cool. So I can I replace the clock that comes with your Apathy theme with this clock? If that's not possible, how do ...
  • Brass Engraved: Thankyou very much for this, worked like a dream!...
  • Patrix: I'm using FeedBurner and the Feedsmith plugin for my filter blog, DesiPundit. I found your post via the WordPress page for RSS feeds ...
  • teddY: @Jessi Hance: Sorry to hear about your experience with Twitter spammers/flamers. I was once a victim of flamers and it sucks that peo...
  • heywho: Hey.... Very Nice...... I'm TOTALLY not a programmer..... but I have this thing I want to do...... so I just decided to start doi...
  • Rodrigo Nunes: NIce SEE MY BLOG http://designrn.wordpress.com/...
  • zubfatal: The Quintessential theme looks great to me, however when scrolling up or down on the page, it makes my laptop work harder than it sho...

Read more recent comments..

Attention: Do NOT follow this link!