public function redirectIfNotUrl($url, array $allowParams = array())
    {
        if ($url != $this->getRequest()->getRequestUri()) {
            $redirect = true;
            $newArgs = array();
            try {
                $tmp = parse_url($this->getRequest()->getRequestUri());
                if (isset($tmp['path']) && $tmp['path'] == $url) {
                    $redirect = false;
                }
                if (isset($tmp['query'])) {
                    parse_str($tmp['query'], $args);
                    $alloweds = array_merge($allowParams, $this->getParameter('nyroDev_utility.redirectIfNotUrl_params', array()));
                    foreach ($alloweds as $k) {
                        if (isset($args[$k])) {
                            $newArgs[$k] = $args[$k];
                        }
                    }
                    $redirect = count($newArgs) != count($args);
                }
            } catch (\Exception $e) {
                $redirect = false;
            }
            if ($redirect) {
                return new RedirectResponse($url.(count($newArgs) ? '?'.http_build_query($newArgs) : ''), 301);
            }
        }

        return false;
    }
public function redirectIfNotUrl($url, array $allowParams = array())
    {
        if ($url != $this->getRequest()->getRequestUri()) {
            $redirect = true;
            $newArgs = array();
            try {
                $tmp = parse_url($this->getRequest()->getRequestUri());
                if (isset($tmp['path']) && $tmp['path'] == $url) {
                    $redirect = false;
                }
                if (isset($tmp['query'])) {
                    parse_str($tmp['query'], $args);
                    $alloweds = array_merge($allowParams, $this->getParameter('nyroDev_utility.redirectIfNotUrl_params', array()));
                    foreach ($alloweds as $k) {
                        if (isset($args[$k])) {
                            $newArgs[$k] = $args[$k];
                        }
                    }
                    $redirect = count($newArgs) != count($args);
                }
            } catch (\Exception $e) {
                $redirect = false;
            }
            if ($redirect) {
                return new RedirectResponse($url.(count($newArgs) ? '?'.http_build_query($newArgs) : ''), 301);
            }
        }

        return false;
    }
public function redirectIfNotUrl ( $ url , array $ allowParams = array ( ) ) { if ( $ url != $ this -> getRequest ( ) -> getRequestUri ( ) ) { $ redirect = true ; $ newArgs = array ( ) ; try { $ tmp = parse_url ( $ this -> getRequest ( ) -> getRequestUri ( ) ) ; if ( isset ( $ tmp [ 'path' ] ) && $ tmp [ 'path' ] == $ url ) { $ redirect = false ; } if ( isset ( $ tmp [ 'query' ] ) ) { parse_str ( $ tmp [ 'query' ] , $ args ) ; $ alloweds = array_merge ( $ allowParams , $ this -> getParameter ( 'nyroDev_utility.redirectIfNotUrl_params' , array ( ) ) ) ; foreach ( $ alloweds as $ k ) { if ( isset ( $ args [ $ k ] ) ) { $ newArgs [ $ k ] = $ args [ $ k ] ; } } $ redirect = count ( $ newArgs ) != count ( $ args ) ; } } catch ( \ Exception $ e ) { $ redirect = false ; } if ( $ redirect ) { return new RedirectResponse ( $ url . ( count ( $ newArgs ) ? '?' . http_build_query ( $ newArgs ) : '' ) , 301 ) ; } } return false ; }
Check if the current URL is matching the desired URL and return a redirect response if not.

@param string $url         The desired URL
@param array  $allowParams List of allowed parameters

@return RedirectResponse|bool
Check if the current URL is matching the desired URL and return a redirect response if not .