If you're a huge Reddit user, and a Feedly one, maybe you know the trick to get the RSS feed of any SubReddit or Reddit page. It consist of adding the .xml (or.rss) suffix to the url you want to integrate into your feeds reader, ex. https://www.reddit.com/.xml or https://www.reddit.com/r/worldnews/.xml.

The problem is, Feedly never seems to refresh the feed, although the rss output is updated regularly. Thanks to a remote webserver and some PHP code, here is the solution to make it finally work:

The Steps

First, we're going to need a server: dedicated, shared or free, it's all good as long as there is some PHP support in it.

Then you have just to upload a new .php file (ex "reddit_rss.php") containing these bits:

header('Content-Type: application/xml; charset=utf-8');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

echo file_get_contents("https://www.reddit.com/r/<yoursub>/new/.xml");

What does that stuff mean?

header('Content-Type: application/xml; charset=utf-8');

Defined as application/atom+xml on Reddit's side, we change it here to a generic xml type in order to maximize compatibility plus getting browser pretty printing.

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); //Already used by Reddit
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

That chunk is the most important, disabling caching of the feed thus forcing refresh.

echo file_get_contents("https://www.reddit.com/r/<yoursub>/new/.xml");

And finally we get the original distant xml to output to the current address, with correct headers and valid formatting.

Then we have just to give the "Reddit RSS Proxy" url to Feedly and suscribe! Now you can follow your favorite subs with ease!

Previous Post Next Post