Grav multisite setup - subsite with subsite

Hello,

i am a Grav newcomer and stuck on a problem for which i could not find any solution in the forum. Hopefully some of you may be ablte to help. At the moment i am trying to customize Grav in a way that i can have multiple subfolders, which in return contain more folders with my subsites.
My folder structure looks like this:

-user
—sites
-----v1
-------sites
---------subsitefolder1
-----------pages (folder)
------------- folder with actual pages inside
---------subsitefolder2
-----v2
-------sites
---------subsitefolder

To make subsites work i created the setup.php(for subdirectory) in Grav’s root directory, unfortunately this only worked for sites which were at the level of my v1 folder. Sites which are located in folders on a deeper level, like my structure above, do not work. Therefore i tried customizing the setup.php, so that it generates the new path correctly. I thought that i matched the path to my folder structure accordingly, but sites are only displayed up to the level of ‘subsitefolder1’. So ‘v1/subsitefolder1’ works, as it shows the landing page but even the actual URL for the landing page ‘v1/subsitefolder1/landingpage’ does not work anymore. This is what my setup.php looks like at the moment:

‘’<?php
/**

  • Multisite setup for sub-directories or path based
  • URLs for subsites.
  • DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
    */
    use Grav\Common\Filesystem\Folder;

// Get relative path from Grav root.
$path = isset($_SERVER[‘PATH_INFO’])
? $_SERVER[‘PATH_INFO’]
: Folder::getRelativePath($_SERVER[‘REQUEST_URI’], ROOT_DIR);

// Extract name of subsite from path
$name = Folder::shift($path);

$prefix = “/{$name}”;

//add another layer for deeper subsites
$subsites= $name . ‘/’ . $path . ‘/’;

//concatenates $name sites and $path"
$urlwithsite=$name . ‘/’ . ‘sites/’ . $path . ‘/’;

// overwrite folder to contain whole path after user/
$folder = “sites/{$urlwithsite}”;

if (!$name || !is_dir(ROOT_DIR . “user/{$folder}”)) {
return ;
}

// Prefix all pages with the name of the subsite
$container[‘pages’]->base($subsites);

return [
‘environment’ => $name,
‘streams’ => [
‘schemes’ => [
‘user’ => [
‘type’ => ‘ReadOnlyStream’,
‘prefixes’ => [
‘’ => [“user/{$folder}”],
]
]
]
]
];

Thanks in advance, any advice is welcome!