isMainRequest()) { return; } $request = $event->getRequest(); $path = $request->getPathInfo(); // Check if the path starts with /wiki if (str_starts_with($path, self::WIKI_PATH_PREFIX)) { // Extract the part after /wiki $subPath = substr($path, strlen(self::WIKI_PATH_PREFIX)); // If subPath is empty or just a slash, redirect to the base URL if (empty($subPath) || $subPath === '/') { $redirectUrl = self::REDIRECT_BASE_URL; } else { // Otherwise, append the subPath to the redirect URL $redirectUrl = self::REDIRECT_BASE_URL . $subPath; } // Create a redirect response $response = new RedirectResponse($redirectUrl, 301); // 301 is permanent redirect $event->setResponse($response); } } public static function getSubscribedEvents(): array { // Use a high priority to intercept the request before the router return [ KernelEvents::REQUEST => ['onKernelRequest', 256], ]; } }