You are here

public function GlobalredirectSubscriber::globalredirectCleanUrls in Global Redirect 8

Detects a q=path/to/page style request and performs a redirect.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The Event to process.

File

src/EventSubscriber/GlobalredirectSubscriber.php, line 105
Contains \Drupal\globalredirect\EventSubscriber\GlobalredirectSubscriber.

Class

GlobalredirectSubscriber
KernelEvents::REQUEST subscriber for redirecting q=path/to/page requests.

Namespace

Drupal\globalredirect\EventSubscriber

Code

public function globalredirectCleanUrls(GetResponseEvent $event) {
  if (!$this->config
    ->get('nonclean_to_clean') || $event
    ->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
    return;
  }
  $request = $event
    ->getRequest();
  $uri = $request
    ->getUri();
  if (strpos($uri, 'index.php')) {
    $url = str_replace('/index.php', '', $uri);
    $event
      ->setResponse(new RedirectResponse($url, 301));
  }
}