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.

Support

Multisite in subdirectory

first-time

Started by Thomas 1 week ago · 2 replies · 49 views
1 week ago

Hey all,

I'm working on a Grav multisite.
I want the base to be in a subdirectory so it wil look somthing like this:
example.com/subdirectory/site1
example.com/subdirectory/site2

But I all assets and links try to ignore the directory and point to
example.com/

My setup.php does look like this:

PHP
<?php
use Grav\Common\Filesystem\Folder;

$raw = $_SERVER['REQUEST_URI'] ?? '/';
$clean = parse_url($raw, PHP_URL_PATH);

$path = isset($_SERVER['PATH_INFO'])
   ? $_SERVER['PATH_INFO']
   : Folder::getRelativePath($clean, ROOT_DIR);

$segments = [];
$pathCopy = $path;

while ($segment = Folder::shift($pathCopy)) {
    $testFolder = "env/" . implode('/', array_merge($segments, [$segment]));

    if (is_dir(ROOT_DIR . "user/{$testFolder}/pages")) {
        $segments[] = $segment;
        $folder = implode('/', $segments);
        $prefix = "/" . implode('/', $segments);
        $name = $folder;

        $container['pages']->base($prefix);

        return [
            'environment' => $name,
            'streams' => [
                'schemes' => [
                    'user' => [
                       'type' => 'ReadOnlyStream',
                       'prefixes' => [
                           '' => ["user/env/{$folder}", "user"],
                       ]
                    ]
                ]
            ]
        ];
    }

    $segments[] = $segment;
}

return [];

Any leads?

3 hours ago

what worked for Rene also worked for me too.

maybe you can share what you have read and did step by step and what did not work etc so we can understand.
at first it wasnt easy for me too but now i just change one php file and put folder in env folder and its done, a new easy website:D

Suggested topics

Topic Participants Replies Views Activity
Support · by Anna, 2 days ago
2 53 6 hours ago
Support · by Justin Young, 7 hours ago
1 23 7 hours ago
Support · by Duc , 7 days ago
2 58 5 days ago
Support · by Colin Hume, 1 week ago
2 51 5 days ago
Support · by Lyn Borchert, 1 month ago
5 156 2 weeks ago