function redirect($to, $options = [])
    {
        return function(\Silex\Application $app) use ($to, $options) {
            $headers  = (array) @$options['headers'];
            $status   = @$options['status'] ?: 302;
            $params   = (array) @$options['params'];
            $absolute = @$options['absolute'] ?: false;

            # Generate URL if the first argument is an existing route name
            if ($route = $app['routes']->get($to)) {
                $to = $app['url_generator']->generate($to, $params, $absolute);
            }

            return new RedirectResponse($to, $status, $headers);
        };
    }