Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Installation & Hosting

Grav multisite setup - subsite with subsite

Started by Marcel 7 years ago · 0 replies · 852 views
7 years ago

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!

Suggested topics

Topic Participants Replies Views Activity
Installation & Hosting · by antoinep, 16 hours ago
5 62 10 hours ago
Installation & Hosting · by Jürgen Dietrich, 7 months ago
0 63 7 months ago
Installation & Hosting · by rappluk, 8 months ago
0 63 8 months ago
Installation & Hosting · by N, 12 months ago
3 75 12 months ago
Installation & Hosting · by Youle, 1 year ago
1 62 1 year ago