Redirect to a new URL, and exit
- optionally set HTTP Response Code (301 = Moved Permanently, 302 = Found)

@param string $url
@param int $httpResponseCode
@param bool $exitAfter - default: true
161497
public function redirect(string $url, int $httpResponseCode = 301, bool $exitAfter = true)
    {
        header('Location: ' . $url, true, $httpResponseCode);
        if ($exitAfter) {
            exit; // After a redirect, we must exit to halt any further script execution
        }
    }
1253835
public static function redirect($location, $stop_execution=true, $code=null) {
	if (preg_match('{^(http(s)?:)?//}', $location) == false) {
		$base_url  = 'http';
		$base_url .= !empty($_SERVER['HTTPS']) ? 's' : '';
		$base_url .= '://'.$_SERVER['SERVER_NAME'];
		
		if (strpos($location, '/') !== 0) {
			$base_url .= '/';
		}
		
		$location = $base_url.$location;
	}
	
	header('Location: '.$location, $replace=true, $code);
	
	if ($stop_execution == false) {
		return;
	}
	
	exit;
}
559379
public function redirect($url, $externalUrl=FALSE) {
	
		// stores enqueued messages for next retrievement
		$this->makeQueuedMessagesPersistent();
		
		if (!$url) return;
		
		// external redirect
		if ($externalUrl) {
			
			header('Location: ' . $url);
			
		// redirect to internal path
		} else {
			
			$router = Router::getInstance();
			$page  = $router->getPage();
			
			if ($page > 1) {
				
				// removes a possible leading slash
				if ('/'==$url{0}) {
					$url = substr($url,1);
				}
				
				// if url contains just module, create a fake action placeholder
				if (FALSE == strpos($url, '/')) {
					$url .= '/';
				}
				
				header('Location: ' . BASE_HREF . $url . '/page-' . $page);
				
			} else {
				
				header('Location: ' . BASE_HREF . $url);
				
			}
				
		}
	
		exit();

	}
744927
protected static function createRedirectResponse($url, $code, $headers)
    {
        $r = new RedirectResponse($url, $code, $headers);
        $r->setRequest(Request::getInstance());

        return $r;
    }
934433
function redirect($url, $type = 303) {
		if ($type === 303) {
			$this->http_response_code(303);
		}
		else if ($type == 301) {
			$this->http_response_code(301);
		}
		else if ($type == 307) {
			$this->http_response_code(307);
		}

		// redirect to...
		$this->header("Location: $url");
	}
1199699
protected function redirectView($url, $statusCode = Response::HTTP_FOUND, array $headers = [])
    {
        return View::createRedirect($url, $statusCode, $headers);
    }
421192
public function redirect($url, $code = HTTP_FOUND, $message = "Moved Permanently", $alerts = [])
    {

        $response = $this->application->response;
        $uri = $this->application->createInstance(Uri::class, [$this->application->request]);

        //Before we redirect, if there are any alerts in the response,
        //Exceptional: Store alerts for future display
        if (!empty($alerts)) {
            $session = $this->application->session;

            //$session->unlock("default"); //unlock the default namespace
            $session->set("alerts", $alerts, "default");
            //$session->update( $session->getId() );
        }

        $response->setStatusCode($code);
        $response->setStatusMessage($message);
        $response->addHeader("Location", $uri->internalize($url));

        $response->sendRedirect();

        $this->abort();
    }
930713
public void redirect(String location, int httpStatusCode) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Redirecting ({} to {}", httpStatusCode, location);
        }
        response.setStatus(httpStatusCode);
        response.setHeader("Location", location);
        response.setHeader("Connection", "close");
        try {
            response.sendError(httpStatusCode);
        } catch (IOException e) {
            LOG.warn("Exception when trying to redirect permanently", e);
        }
    }
595748
public static function httpToVendor($httpCode = HttpCode::HTTP_OK): int
    {
        if ($httpCode < 400) {
            return Code::OK;
        }

        switch ($httpCode) {
            case HttpCode::HTTP_CLIENT_CLOSED_REQUEST:
                return Code::CANCELLED;

            case HttpCode::HTTP_INTERNAL_SERVER_ERROR:
                return Code::INTERNAL;

            case HttpCode::HTTP_GATEWAY_TIMEOUT:
                return Code::DEADLINE_EXCEEDED;

            case HttpCode::HTTP_NOT_FOUND:
                return Code::NOT_FOUND;

            case HttpCode::HTTP_CONFLICT:
                return Code::ALREADY_EXISTS;

            case HttpCode::HTTP_FORBIDDEN:
                return Code::PERMISSION_DENIED;

            case HttpCode::HTTP_UNAUTHORIZED:
                return Code::UNAUTHENTICATED;

            case HttpCode::HTTP_TOO_MANY_REQUESTS:
                return Code::RESOURCE_EXHAUSTED;

            case HttpCode::HTTP_PRECONDITION_FAILED:
                return Code::FAILED_PRECONDITION;

            case HttpCode::HTTP_NOT_IMPLEMENTED:
                return Code::UNIMPLEMENTED;

            case HttpCode::HTTP_SERVICE_UNAVAILABLE:
                return Code::UNAVAILABLE;

            default:
                if ($httpCode >= 500) {
                    return Code::INTERNAL;
                }

                if ($httpCode >= 400) {
                    return Code::INVALID_ARGUMENT;
                }

                return Code::OK;
        }
    }
617274
function redirect(int $code, string $url): \Nofuzz\Http\HTTPResponse
  {
    $this->setStatusCode($code);
    $this->setHeader('Location',$url);
    $this->setBody('');

    return $this;
  }
1029592
public function redirectTo( $url = 0, $code = 302 ) {
		if ( $url === null ) {
			$this->redirectTo = null;
			return true;
		}
		if ( !is_string( $url ) || !is_int( $code ) ) {
			return false;
		}
		$this->redirectTo = [ $url, $code ];
		return true;
	}
1221877
public function redirect($url = null, $statusCode = 302, $options = array())
    {
        $this->setStatusCode($statusCode);
        $this->setOption($options);

        // The variables for custom redirect view
        $escapedUrl = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
        $wait = (int)$this->redirectWait;

        // Location header does not support delay
        if (0 === $wait) {
            $this->setHeader('Location', $url);
        }

        // Prepare response content
        if ($this->redirectView) {
            ob_start();
            require $this->redirectView;
            $content = ob_get_clean();
        } else {
            $content = sprintf('<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="refresh" content="%d;url=%2$s">
    <title>Redirecting to %s</title>
  </head>
  <body>
    <h1>Redirecting to <a href="%2$s">%2$s</a></h1>
  </body>
</html>', $wait, $escapedUrl);
        }

        return $this->setContent($content);
    }
870978
protected function redirect($url, $code = 302)
    {
        if (!headers_sent()) {
            if (SERVER_MODE === 'swoole' ) {
                $GLOBALS['__$response']->status($code);
            } else if ($code == 301) {
                header('HTTP/1.1 301 Moved Permanently');
            } else {
                header('HTTP/1.1 302 Found');
            }

            $this->setHeader("Location", $url);
            $this->stopRun();
        } else {
            echo '<html><head><meta charset="UTF-8" /><title></title></head><body>';
            echo '<script>window.location.href="'. $url .'";</script></body></html>';
            $this->stopRun();
        }
    }
618965
public void redirect(String location, int statusCode) {
        checkCommitted();
        finalizeResponse();

        status(statusCode);
        header(HttpConstants.Header.LOCATION, location);
        header(HttpConstants.Header.CONNECTION, "close");
        try {
            httpServletResponse.sendError(statusCode);
        } catch (IOException e) {
            throw new PippoRuntimeException(e);
        }
    }
1177001
public function toUrl($url, $statusCode = 302)
    {
        $server = $this->getServer();

        $response = $server->getResponse(false)
            ->withHeader('Location', $url)
            ->withStatus($statusCode);

        return $response;
    }
369201
protected function redirect(string $url, array $parameters = [], int $httpResponseCode = 307)
    {
        $query = '';
        // Making URL query string if parameters given.
        if (!empty($parameters)) {
            $query = '?';
            if (parse_url($url, PHP_URL_QUERY)) {
                $query = '&';
            }
            $query .= http_build_query($parameters);
        }

        header('Location: ' . $url . $query, true, $httpResponseCode);
        exit;
    }
971720
public function redirectTo($uri, $type = 'location', $httpResponseCode = 302)
    {
        $uri = str_replace(['.', '/'], '/', $uri);

        if (!preg_match('#^https?://#i', $uri)) {
            $uri = $this->sitePath($uri);
        }

        switch ($type) {
            case 'refresh':
                header('Refresh:0;url='.$uri);
                break;
            case 'location':
                header('Location: '.$uri, true, $httpResponseCode);
                break;
        }
        exit;
    }