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

Multisite in subdirectory

first-time

Started by Thomas 4 weeks ago · 3 replies · 304 views
4 weeks 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 weeks 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

3 weeks ago

@thms, Any progress you could share?

Suggested topics

Topic Participants Replies Views Activity
Support · by BenLaKnet, 5 days ago
1 116 2 days ago
Support · by BenLaKnet, 1 week ago
5 193 2 days ago
Support · by kskt, 2 days ago
0 42 2 days ago
Support · by David Meissner, 2 days ago
0 38 2 days ago
Support · by David Meissner, 3 days ago
3 88 3 days ago