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

Multisite in subdirectory

first-time

Started by Thomas 2 months ago · 3 replies · 418 views
2 months 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?

1 month 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

1 month ago

@thms, Any progress you could share?

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 6 days ago
12 211 13 hours ago
Support · by gtx, 3 days ago
2 124 2 days ago
Support · by Anna, 2 weeks ago
9 297 3 days ago
Support · by TomW, 1 week ago
4 162 6 days ago
Support · by Anna, 1 week ago
4 171 7 days ago