public function redirectMatching(Request $request)
    {
        $redirects = $this->storage->getRedirects()->getRedirects();
        $relativeUri = '/' . $request::$relativeUri;

        foreach ($redirects as $redirect) {
            if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
                $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
                if (substr($toUrl, 0, 1) == '/') {
                    $toUrl = substr($toUrl, 1);
                }
                if ($redirect->type == '301') {
                    header('HTTP/1.1 301 Moved Permanently');
                    header('Location: ' . $request::$subfolders . $toUrl);
                    exit;
                } elseif ($redirect->type == '302') {
                    header('Location: ' . $request::$subfolders . $toUrl, true, 302);
                    exit;
                } else {
                    throw new \Exception('Invalid redirect type.');
                }
            }
        }
    }
public function redirectMatching(Request $request)
    {
        $redirects = $this->storage->getRedirects()->getRedirects();
        $relativeUri = '/' . $request::$relativeUri;

        foreach ($redirects as $redirect) {
            if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
                $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
                if (substr($toUrl, 0, 1) == '/') {
                    $toUrl = substr($toUrl, 1);
                }
                if ($redirect->type == '301') {
                    header('HTTP/1.1 301 Moved Permanently');
                    header('Location: ' . $request::$subfolders . $toUrl);
                    exit;
                } elseif ($redirect->type == '302') {
                    header('Location: ' . $request::$subfolders . $toUrl, true, 302);
                    exit;
                } else {
                    throw new \Exception('Invalid redirect type.');
                }
            }
        }
    }
public function redirectMatching ( Request $ request ) { $ redirects = $ this -> storage -> getRedirects ( ) -> getRedirects ( ) ; $ relativeUri = '/' . $ request :: $ relativeUri ; foreach ( $ redirects as $ redirect ) { if ( preg_match_all ( $ redirect -> fromUrl , $ relativeUri , $ matches ) ) { $ toUrl = preg_replace ( $ redirect -> fromUrl , $ redirect -> toUrl , $ relativeUri ) ; if ( substr ( $ toUrl , 0 , 1 ) == '/' ) { $ toUrl = substr ( $ toUrl , 1 ) ; } if ( $ redirect -> type == '301' ) { header ( 'HTTP/1.1 301 Moved Permanently' ) ; header ( 'Location: ' . $ request :: $ subfolders . $ toUrl ) ; exit ; } elseif ( $ redirect -> type == '302' ) { header ( 'Location: ' . $ request :: $ subfolders . $ toUrl , true , 302 ) ; exit ; } else { throw new \ Exception ( 'Invalid redirect type.' ) ; } } } }
Loop through the redirects and see if a redirect needs to take place

@param Request $request
@throws \Exception
Loop through the redirects and see if a redirect needs to take place