<?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);
$folder = "sites/{$name}";
$prefix = "/{$name}";
if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
return [];
}
// Prefix all pages with the name of the subsite
$container['pages']->base($prefix);
return [
'environment' => $name,
'streams' => [
'schemes' => [
'user' => [
'type' => 'ReadOnlyStream',
'prefixes' => [
'' => ["user/{$folder}"],
]
]
]
]
];
If you choose sub-directories or path based URLs for subsites, then the only thing you need is to create a directory for each subsite in the user/sites directory containing at least the required folders config, pages, plugins and themes.
What contents should these folders have? How do required plugins get installed? How does the grav-admin fit in?
<?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'], dirname($_SERVER['SCRIPT_NAME']));
$path = preg_replace('|[?#].*$|', '', $path);
// Extract name of subsite from path
$name = Folder::shift($path);
$folder = "sites/{$name}";
$prefix = "/{$name}";
if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
return [];
}
// Prefix all pages with the name of the subsite
$container['pages']->base($prefix);
return [
'environment' => $name,
'streams' => [
'schemes' => [
'user' => [
'type' => 'ReadOnlyStream',
'prefixes' => [
'' => ["user/{$folder}"],
]
]
]
]
];
Got it working.
I made two different grav (with admin included) installations. Main-web and sub-web. On main-web I installed a blog theme and on sub-web i installed knowledge-base theme. Then copied accounts, data, pages, config, themes, plugins from sub-web into the user/sites/docs folder in main-web.
Now I have a blog working at localhost:8000 and localhost:8000/admin
And a knowledge base at localhost:8000/docs and localhost:8000/docs/admin
Hey guys, I’m reading through this thread and this is exactly what I want to do. Dumb question, do I need a “setup.php” and a “setup_subdomain.php” …or just the “setup.php” file with the sub domain code snippet in it?
Hey Tuttle, thanks for the quick reply! I just tried that, but now I’m just not sure what to do next… Should I be seeing something in my admin? …kind of lost on what/where to go now?