Aerys\Host::redirect PHP Method

redirect() public method

NOTE: the redirect URI must match the format "scheme://hostname.tld" (with optional port and path). The following example redirects all unencrypted requests to the equivalent encrypted resource: setName("mysite.com"); $host->redirect("https://mysite.com");
public redirect ( string $absoluteUri, integer $redirectCode = 307 ) : Host
$absoluteUri string The location to which we wish to redirect
$redirectCode integer The HTTP redirect status code (300-399)
return Host
    public function redirect(string $absoluteUri, int $redirectCode = 307) : Host
    {
        if (!($url = @parse_url($absoluteUri))) {
            throw new \DomainException("Invalid redirect URI");
        }
        if (empty($url["scheme"]) || $url["scheme"] !== "http" && $url["scheme"] !== "https") {
            throw new \DomainException("Invalid redirect URI; \"http\" or \"https\" scheme required");
        }
        if (isset($url["query"]) || isset($url["fragment"])) {
            throw new \DomainException("Invalid redirect URI; Host redirect must not contain a query or fragment component");
        }
        $redirectUri = rtrim($absoluteUri, "/") . "/";
        if ($redirectCode < 300 || $redirectCode > 399) {
            throw new \DomainException("Invalid redirect code; code in the range 300..399 required");
        }
        $this->redirect = static function (Request $req, Response $res) use($redirectUri, $redirectCode) {
            $res->setStatus($redirectCode);
            $res->setHeader("location", $redirectUri . \ltrim($req->getUri(), "/"));
            $res->end();
        };
        return $this;
    }