src/services/RedirectsService.php
public function onException (ExceptionEvent $event)
	{
		$exception = $event->exception;
		$craft = \Craft::$app;

		if (!($exception instanceof HttpException) || $exception->statusCode !== 404)
			return;

		$path = $craft->request->getFullPath();
		$query = $craft->request->getQueryStringWithoutPath();

		if ($query)
			$path .= '?' . $query;

		if ($redirect = $this->findRedirectByPath($path))
		{
			$event->handled = true;
			$craft->response->redirect($redirect['to'], $redirect['type'])
			                ->send();
			$craft->end();
		}
	}
public function onException (ExceptionEvent $event)
	{
		$exception = $event->exception;
		$craft = \Craft::$app;

		if (!($exception instanceof HttpException) || $exception->statusCode !== 404)
			return;

		$path = $craft->request->getFullPath();
		$query = $craft->request->getQueryStringWithoutPath();

		if ($query)
			$path .= '?' . $query;

		if ($redirect = $this->findRedirectByPath($path))
		{
			$event->handled = true;
			$craft->response->redirect($redirect['to'], $redirect['type'])
			                ->send();
			$craft->end();
		}
	}
Handles 404 exceptions

@param ExceptionEvent $event

@return void
@throws \yii\base\Exception
@throws \yii\base\ExitException