redirect wiki pages to qualiwiki website
This commit is contained in:
parent
d68f738a4b
commit
8c1380ec04
2 changed files with 99 additions and 0 deletions
51
src/EventSubscriber/WikiRedirectSubscriber.php
Normal file
51
src/EventSubscriber/WikiRedirectSubscriber.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
class WikiRedirectSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private const WIKI_PATH_PREFIX = '/wiki';
|
||||
private const REDIRECT_BASE_URL = 'https://qualiwiki.cipherbliss.com/wiki';
|
||||
|
||||
public function onKernelRequest(RequestEvent $event): void
|
||||
{
|
||||
// Don't do anything if it's not the master request
|
||||
if (!$event->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],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue