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 · 535 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?

2 months 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

2 months ago

@thms, Any progress you could share?

Suggested topics

Topic Participants Replies Views Activity
Support · by Paul Hodges, 4 weeks ago
19 483 5 days ago
Support · by Lauw, 7 days ago
2 99 6 days ago
Support · by Anna, 2 weeks ago
4 426 1 week ago
Support · by gtx, 4 weeks ago
4 377 3 weeks ago
Support · by Anna, 1 month ago
9 483 3 weeks ago