Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Multisite in subdirectory

first-time

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

3 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

3 months ago

@thms, Any progress you could share?

Suggested topics

Topic Participants Replies Views Activity
Support · by Marcel, 4 days ago
0 81 4 days ago
Support · by JakobDB, 6 days ago
1 89 5 days ago
Support · by ramenos, 7 days ago
3 103 6 days ago
Support · by gravinator, 2 weeks ago
3 228 7 days ago
Support · by Roger Parkinson, 2 weeks ago
3 308 2 weeks ago