Routes to a folder (manually maintained) outside kirby content folder

Hello

From our actual static website we have to take over an folder with large downloads to our new kirby website and URL to this download folder (manually maintained) can not be altered as URLs are used by customers over years. Actually the url is : https://my.site.com/downloads/.../...

In our new kirby installation we would like to put the downloads folder at root as:

  • assets
  • index.php
  • content
  • downloads
  • index.php
  • kirby

How is the correct kirby routes definition in config.php in order that the url https://my.site.com/downloads/.../... points/redirects to the downloads folder and all its files and subfolders? Actuall my routes definition starts with, but I could not figure out which response object should be used in the action function:

    'routes' => [
        [
            'pattern' => 'downloads/(:all)',
            'language' => '*',
            'action' => function () {
            ????
           }

many thanks in advance

If I understand correctly, these are download links and the corresponding file should be downloaded when the url is called?

In that case, you might want to return a download response: Response::download() | Kirby CMS

Check out the Response class for different response types: Response | Kirby CMS

Many thanks for the prompte reponse:

in the download folder are files like pds, images, zips etc. for download but also html- and xml-files that should be rendered at their url-position in a “normal” way as for a static site.

Ok, then you need some sort of logic that checks if the file exists in the first place and then returns responses depending on file extension or mime type.

Many thanks again.

I “resolved” it with Response::download() for all file types (also css etc.) as Response::download() does include mime/type resolving and file exist testing (and more):

    'routes' => [
        [
            'pattern' => 'downloads/(:all)',
            'language' => '*',
            'action' => function ($file) {
                $downloads_path = '../downloads/';
                $file_path = $downloads_path . $file;
                return Response::download($file_path, null);
            }
        ]

best regards