<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class UrlEventSubscriber implements EventSubscriberInterface
{
public function onKernelRequest(RequestEvent $event)
{
//$schemeAndHttpHost = $event->getRequest()->getSchemeAndHttpHost();
$basePath = $event->getRequest()->getBasePath();
$uri = $event->getRequest()->getUri();
$pattern = "/\/staff[_|-].*\/public/";
if (preg_match($pattern, $basePath)) {
$url = preg_replace($pattern, '', $uri);
//$event->setResponse(new RedirectResponse($schemeAndHttpHost, 302));
$event->setResponse(new RedirectResponse($url, 301));
}
}
public static function getSubscribedEvents(): array
{
return [
RequestEvent::class => 'onKernelRequest',
];
}
}