RSS Feed is served as a downloadable file instead of a page

I have two rss feeds on my website. One of them use @bnomei RSS feed plugin and the other one is a custom implementation for my podcasts. They both finish in /feed.

Each time I access the urls, instead of showing me the page with the content of the xml file, a file named “feed” is available to download. If I download it and open it, the file is perfectly fine. I thought it was a server thing but apparently no.

I tried using $kirby->response()->type('rss'); in my template but it didn’t change anything. I’m using the latest version of kirby.

Here’s my feed.php template file :

<?php
$kirby->response()->type('rss'); 
$language = $kirby->language();
$options = [
    'en' => [
        'url' => site()->url(),
        'feedurl' => site()->url() . '/feed/',
        'title' => 'Latest articles',
        'description' => 'Read the latest news about our company',
        'link' => site()->url(),
        'urlfield' => 'url',
        'titlefield' => 'title',
        'datefield' => 'date',
        'textfield' => 'text',
        'modified' => time(),
        'snippet' => 'feed/rss', // 'feed/json'
        'mime' => null,
        'sort' => true,
    ],
    'fr' => [
        'url' => site()->url(),
        'feedurl' => site()->url() . '/feed/',
        'title' => 'Derniers articles',
        'description' => 'Nos dernières publications',
        'link' => site()->url(),
        'urlfield' => 'url',
        'titlefield' => 'title',
        'datefield' => 'date',
        'textfield' => 'text',
        'modified' => time(),
        'snippet' => 'feed/rss', // 'feed/json'
        'mime' => null,
        'sort' => true,
    ],
];

$frContent = page(['articles', 'podcasts']);
$enContent = page('articles');
$feedContent;

if($language == "fr") {
  $feedContent = $frContent;
} else {
  $feedContent = $enContent;
}

$feed = $feedContent
    ->children()
    ->listed()
    ->filter(function ($page) use($language) {
        return $page->translation($language->code())->exists(); 
    })  
    ->sortBy(function ($page) {
      return $page->date()->toDate();
      }, 'desc')
    ->feed($options[$language->code()]);

echo $feed;
?>

Any tips on how to get this working?

Edit: on Firefox it gives me the file to download, on chromium the page is shown as text.

1 Like

Update: I tried turning the RSS feed made with bnomei plugin to json and it works. I also tried a previous install of kirby2 with RSS feeds inside on my live server and they are showing fine. There must be something I don’t get about the RSS config or in kirby. :confused:

Hm, would have to look into it again, but used the RSS variant of @bnomei’s plugin recently in two projects without any issues :thinking:. Was there an update recently?

Since the “bug” also appears on my own RSS implementation, it’s probably not related to bnomei plugin. Maybe I can configure a route in the config.php file to tell kirby to return a text/rss file?

Another solution I found was to rename my templates into feed.xml.php and go to /feed.xml. It doesn’t bother me that much to have the .xml extension to be honest so if we can’t find a way I’ll go this route.

it was updated with a minor check for empty list of items but the rendering/mime type logic was not altered.
but maybe the “bug” is older. as far as i can tell the plugin always caused firefox to open a download window. other feeds do not seem to cause this… maybe setting the mime type is still broken (but i am a but at a loss what to do since i tried fixing that before).

on closer inspection this might be caused if a route is used and kirby triggers a 301 before returning the content?

I actually get the same result with a download prompt, but only in FF, Safari tells me there is no reader installed and Chrome shows the xml. But the content type header is perfectly ok. This is what I get from a request with Rested app:

HTTP/1.1 200 OK

X-Content-Type-Options: nosniff
Content-Type: application/rss+xml; charset=UTF-8
Server: nginx
Strict-Transport-Security: max-age=172800
Transfer-Encoding: Identity
Date: Fri, 14 Feb 2020 20:23:54 GMT
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
Referrer-Policy: strict-origin-when-cross-origin
Connection: keep-alive

This is no Kirby problem, I think in other browsers it may be simular, but I don’t know, because FF is MY browser!!!

On FF you should download an Add-On called “RSSPreview” to view an RSS-Feed.

FF has removed support for RSS in versions 64+, including the useful preview feature.