Hello,
I am having an issue running Radicle on Laravel Herd/Valet. No matter what I do, I am stuck in the following loop:
- on the main site all works as expected, no issues there
- on any subsite the most I can get is redirect to the root of the website - cannot load wp-admin or any other page or post on the frontend
This is my Valet driver, any help will be appreciated.
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\BasicValetDriver;
class BedrockMultisiteValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri): bool
{
return file_exists($sitePath . '/public/content/mu-plugins/00-acorn-boot.php') ||
file_exists($sitePath . '/web/app/mu-plugins/bedrock-autoloader.php') ||
(is_dir($sitePath . '/web/app/') &&
file_exists($sitePath . '/web/wp-config.php') &&
file_exists($sitePath . '/bedrock/application.php'));
}
/**
* Determine if the incoming request is for a static file.
*
* @return string|false
*/
public function isStaticFile(string $sitePath, string $siteName, string $uri): bool
{
$uri = $this->rewriteMultisite($sitePath, $uri);
$staticFilePath = $sitePath . '/public/wp' . $uri;
if ($this->isActualFile($staticFilePath)) {
return $staticFilePath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
$uri = $this->rewriteMultisite($sitePath, $uri);
$_SERVER['PHP_SELF'] = $uri;
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
return parent::frontControllerPath(
$sitePath . '/public',
$siteName,
$this->forceTrailingSlash($uri)
);
}
/**
* Imitate the rewrite rules for a multisite .htaccess
*/
protected function rewriteMultisite(string $sitePath, string $uri): string
{
if (!$this->isMultisite($sitePath)) {
return $uri;
}
if (preg_match('#^(/[^/]+)?(?!/wp-json)(/wp-.*)#', $uri, $matches) || preg_match('#^(/[^/]+)?(/.*\.php)#', $uri, $matches)) {
return "/wp{$matches[2]}";
}
return $uri;
}
/**
* Determine if Bedrock installer is Multisite
*/
protected function isMultisite(string $sitePath): bool
{
$app = file_get_contents($sitePath . '/bedrock/application.php');
/** {@link https://github.com/fewagency/best-practices/blob/893dfef52442eb3c4aafc197926f29dee83f3cd0/Wordpress/WordPressMultisiteValetDriver.php#L37 Regex poached from similar driver} */
return !! preg_match("/MULTISITE/", $app);
// return !! preg_match("/define\(\s*('|\")MULTISITE\\1\s*,\s*true\s*\)/mi", $app);
}
/**
* Redirect to uri with trailing slash.
*
* @param string $uri
* @return string
*/
private function forceTrailingSlash($uri)
{
if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
header('Location: ' . $uri . '/');
exit;
}
return $uri;
}
}
Best!