Video not loading

In case you really want to serve it from the content folder, I just had to do this myself, because I don’t want to copy 500MB - 2GB files around for every page/directory change (and the copying seems to break on my hoster), so here’s what I did (thanks to @jimbobrjames and this thread):

  • Add a new plugin directory (e.g. contentfiles)
  • Create a new index.php in said directory
  • Add the code from the following snippet
  • Adjust the .htaccess rule as shown below
  • Be aware of the potential downsides, risks and breaking things, by circumventing Kirby 3’s design decision :sweat_smile:
  • Enhance as you like
<?php

Kirby::plugin('yourname/contentfiles', [
    'options' => [
        'extenions' => [
            'mp4'
        ]
    ],
    'components' => [
        'file::url' => function (Kirby $kirby, $file)
        {
            $page = $file->parent();

            if (in_array($file->extension(), option('yourname.contentfiles.extenions')))
            {
                return $kirby->url() . '/content/' . $page->diruri() . '/' . $file->filename();
            }
            else
            {
                return $file->mediaurl();
            }
        }
    ]
]);
# block all files except videos in the content folder from being accessed directly
RewriteRule !^content/(.*).mp4 - [C]
RewriteRule ^content/(.*) index.php [L]