-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from hughbris/multisite-subdir
Add support for multisite installs using subdirectories
- Loading branch information
Showing
7 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ RUN \ | |
EXPOSE 80 443 | ||
|
||
COPY root/ / | ||
COPY env/ /tmp/env/ | ||
|
||
WORKDIR /var/www/grav | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,6 @@ EXPOSE 80 443 | |
COPY root/ / | ||
|
||
WORKDIR /var/www/grav | ||
COPY env/ /tmp/env/ | ||
|
||
CMD ["/init-admin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Multisite setup for sub-directories or path based | ||
* URLs for subsites. | ||
* | ||
* DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING! | ||
*/ | ||
|
||
use Grav\Common\Filesystem\Folder; | ||
|
||
// Get relative path from Grav root. | ||
$path = isset($_SERVER['PATH_INFO']) | ||
? $_SERVER['PATH_INFO'] | ||
: Folder::getRelativePath($_SERVER['REQUEST_URI'], ROOT_DIR); | ||
|
||
// Extract name of subsite from path | ||
$name = Folder::shift($path); | ||
$folder = "sites/{$name}"; | ||
$prefix = "/{$name}"; | ||
|
||
if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) { | ||
return []; | ||
} | ||
|
||
// Prefix all pages with the name of the subsite | ||
$container['pages']->base($prefix); | ||
|
||
return [ | ||
'environment' => $name, | ||
'streams' => [ | ||
'schemes' => [ | ||
'user' => [ | ||
'type' => 'ReadOnlyStream', | ||
'prefixes' => [ | ||
'' => ["user/{$folder}"], | ||
] | ||
] | ||
] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Multisite setup for subsites accessible via sub-domains. | ||
* | ||
* DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING! | ||
*/ | ||
|
||
use Grav\Common\Utils; | ||
|
||
// Get subsite name from sub-domain | ||
$environment = isset($_SERVER['HTTP_HOST']) | ||
? $_SERVER['HTTP_HOST'] | ||
: (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'); | ||
// Remove port from HTTP_HOST generated $environment | ||
$environment = strtolower(Utils::substrToString($environment, ':')); | ||
$folder = "sites/{$environment}"; | ||
|
||
if ($environment === 'localhost' || !is_dir(ROOT_DIR . "user/{$folder}")) { | ||
return []; | ||
} | ||
|
||
return [ | ||
'environment' => $environment, | ||
'streams' => [ | ||
'schemes' => [ | ||
'user' => [ | ||
'type' => 'ReadOnlyStream', | ||
'prefixes' => [ | ||
'' => ["user/{$folder}"], | ||
] | ||
] | ||
] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters