forked from nextcloud/server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IONOS: feat(base): add "redirect" config
The "redirects" config allows configuring redirects from paths to routes. Example config: "redirects" => { "^/path/regexp" => "an.apps.controller.route.locator" } Use case: * An administrator can configure another app as target for certain paths. Differentiation from Apache redirects: * this allows configuring redirects in one place and avoids spreading the configuration in multiple places. * the target route locator is more expressive/easier to trace than a path Signed-off-by: Thomas Lehmann <[email protected]>
- Loading branch information
1 parent
b066e24
commit db33426
Showing
2 changed files
with
41 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
* @author Tobia De Koninck <[email protected]> | ||
* @author Vincent Petry <[email protected]> | ||
* @author Volkan Gezer <[email protected]> | ||
* @author Thomas Lehmann <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -1047,7 +1048,27 @@ public static function handleRequest(): void { | |
OC_App::loadApps(['filesystem', 'logging']); | ||
OC_App::loadApps(); | ||
} | ||
Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo()); | ||
$requestPath = $request->getRawPathInfo(); | ||
$redirects = $systemConfig->getValue('redirects', []); | ||
|
||
if ($redirects) { | ||
foreach ($redirects as $fromPattern => $toLocator) { | ||
if (!preg_match('/' . $fromPattern . '/', $requestPath)) { | ||
continue; | ||
} | ||
|
||
try { | ||
$targetLocation = Server::get(IURLGenerator::class)->linkToRouteAbsolute($toLocator); | ||
header('Location: ' . $targetLocation); | ||
return; | ||
} catch (\Exception) { | ||
// In case of container exceptions or | ||
// route not found exceptions we proceed as usual. | ||
} | ||
} | ||
} | ||
|
||
Server::get(\OC\Route\Router::class)->match($requestPath); | ||
return; | ||
} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { | ||
//header('HTTP/1.0 404 Not Found'); | ||
|