Rewrite Drupal RSS XML feeds to Feedburner to get a count

TranceDesign.net is a DJ Mix podcast that was the idea of my friend CharlieF and myself. We have been running the podcast for a few years, and although originally I wanted to record my own DJ Mix weekly to add in, life got busier and it was hard to maintain. At first we built the RSS XML and HTML files by hand when a new mix was uploaded. This got boring for me, so I put up a Drupal 6 site with the Audio modules and custom views to take care of things automatically. So far it has been pretty nice to be able to upload everything and organize data within Drupal, however I often wondered how many subscribers we had. I could estimate how many after posting a new mix, but after a recent mix the number started to fall. I’ll get to that later, though.

I decided it was time to redirect the feed to Feedburner so we could use their fun widgets and stats. In order to save CPU, I would often wget the files from Drupal so that Apache just had to serve a static file. This also takes care of that.

There are some important exemptions that need to be taken into consideration. For one, the iTunes store caches data and Feedburner checks every 30 minutes. I wanted the iTunes store to also have the raw XML feed, since Feedburner has a 550K limit on how much of a feed it carries. There are actually two feeds. One for iTunes that just has the podcast media enclosure, summary, and details. The second is an RSS feed that contains the full tracklistings as they appear on the site for use in readers. I decided that I also wanted the Trance Design Facebook page take the feed from the server, since it is quite slow to update and this lets me tier the notifications. Facebook also sends the note to Twitter.com/trancedesign automatically, so the sooner the better. It is actually quite nice to have a landing page at Feedburner so anyone can see their choice of reader in order to subscribe. For the easy-going, there has always been a direct link to the iTunes music store where one may subscribe.

So here are my mod_rewrite rules for the .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner/* [OR]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator* [OR]
RewriteCond %{HTTP_USER_AGENT} !iTMS* [OR]
RewriteRule ^trancedesign\.xml$ http://feeds.feedburner.com/TranceDesign [R=302,L]

RewriteCond %{HTTP_USER_AGENT} !FeedValidator* [OR]
RewriteCond %{HTTP_USER_AGENT} !FacebookFeedParser* [OR]
RewriteCond %{HTTP_USER_AGENT} !FeedBurner/*
RewriteRule ^rss\.xml$ http://feeds.feedburner.com/trancedesign-full [R=302,L]

Finding the user agent for Apple’s iTunes Music Store required some log grepping, and the user agent iTMS comes from Apple’s IP block range. That out of the way, I was then able to use FeedBurner’s Optimize tab and enable BrowserFriendly’s redirection option. This places the original URL in the list for subscriptions, and lets me use FeedBurner to count how many unique subscribers we have while not permanently redirecting the traffic away from the site. Since FeedBurner is not redirected to itself, it will have the most up to date feed from the site.

Now I get some fun widgets to display on the page:
Regular subscribers:  Rewrite Drupal RSS XML feeds to Feedburner to get a count
Full Tracklisting subscribers:  Rewrite Drupal RSS XML feeds to Feedburner to get a count

It has only been a day since I made the change, and some issues I’ve been having with the site on the new host have made the download URLs sometimes return a 404. I’ve been tracking this down and it seems to have to do with having caching enabled.

I was seeing in my error_log: Premature end of script headers: and internal_error.html in my database log.

Hopefully this fixes the problem, as it has surely been frustrating when somebody tries to download a file and then unsubscribes. I was fairly certain we had at least 600+ subscribers, but since I’ve been putting up mixes of different genres, this could also turn some people off from the podcast entirely. Still, it is nice to have a place to post mixes when I find good ones or when I can get around to publishing a mix.

Since the site is now hosted with Dreamhost, I found a rule on Ravi Sagar’s blog that also helps to see the analog statistics they provide that Drupal and other sites that use rewrite rules prohibit you from seeing.

RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/failed_auth.html$
RewriteRule ^.*$ - [L]

I got the gist of this idea from a Perishable Press post, however since Feedburner’s user agent is FeedBurner/1.0 adding wildcards to the RewriteCond was necessary to make it work. Otherwise, Feedburner just pulled the feed from itself.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments 2

  1. Dave Reid wrote:

    You could also have the FeedBurenr module redirect people to the proper feed for you! http://drupal.org/project/feedburner

    Posted 24 Sep 2009 at 11:50 pm
  2. rayrayisforever wrote:

    Absolutely! I ran into problems with Dreamhost and my Drupal 6 installation when I moved it. For some reason, during, before, and after cron.php runs, people would get 404 pages when trying to download a mix. All the support posts I found were concerning a module that I did not have installed, and the problem only went away after removing about 7 modules. I haven't had the issue since, but I decided to just use an .htaccess file.

    For my next site, I'm definitely going to use this :D Thanks!

    Posted 25 Sep 2009 at 11:46 am

Post a Comment

Your email is never published nor shared. Required fields are marked *

Improve the web with Nofollow Reciprocity.