Redirect from www.hostname to hostname

@return Application
495640
public function killWww()
    {
        $host = $_SERVER['SERVER_NAME'];
        if (stripos($host, 'www.') === 0) {
            $host = substr_replace($host, '', 0, 4);
            $uri = $_SERVER['REQUEST_URI'];
            header("HTTP/1.1 301 Moved Permanently");

            if ('/' == $uri[0]) {
                header('Location: http://' . $host . $uri);
            } else {
                header('Location: http://' . $host . '/' . $uri);
            }

            die;
        }

        return $this;
    }
329627
protected function getRedirectUrl()
    {
        $url = $this->redirector->getUrlGenerator();

        if ($this->redirect) {
            return $url->to($this->redirect);
        } elseif ($this->redirectRoute) {
            return $url->route($this->redirectRoute);
        } elseif ($this->redirectAction) {
            return $url->action($this->redirectAction);
        }

        return $url->previous();
    }
243314
private function getRedirectUrlFromRequest()
    {
        $request  = $this->application->getRequest();
        $redirect = $request->getQuery('redirect');
        if ($redirect && $this->urlWhitelisted($redirect)) {
            return $redirect;
        }

        $redirect = $request->getPost('redirect');
        if ($redirect && $this->urlWhitelisted($redirect)) {
            return $redirect;
        }

        return false;
    }
1047657
public function redirect()
    {
        $this->request->getSession()->set(
            'oauth.temp', $temp = $this->server->getTemporaryCredentials()
        );

        return new RedirectResponse($this->server->getAuthorizationUrl($temp));
    }
514275
static public function web()
	{
	    $key = 'app.web';
	    if (!static::has($key)) {
	        if ( !($app = static::app()) || $app->isCli()) {
	            static::setShared($key, new \Wslim\Web\App(Config::getWebAppPath()));
	        } else {
	            static::setShared($key, $app);
	        }
	    }
	    
	    return static::get($key);
	}
240693
public function redirect()
    {
        if (isset($_GET['template']) === false) {
            return redirect($this->router->generate('navigations-page'));
        } else {
            return 'Redirect: ' . $this->router->generate('navigations-page');
        }
    }
398231
protected function getDomain()
    {
        if (!empty($this->sDomain)) {
            return $this->sDomain;
        } elseif (site_url() === '/') {
            $oInput    = Factory::service('Input');
            $sHost     = $oInput->server('SERVER_NAME');
            $sProtocol = $oInput->server('REQUEST_SCHEME') ?: 'http';
            if (empty($sHost)) {
                throw new HostNotKnownException('Failed to resolve host; email links will be incomplete.');
            } else {
                $this->sDomain = $sProtocol . '://' . $sHost . '/';
            }
        } else {
            $this->sDomain = site_url();
        }

        $this->sDomain = rtrim($this->sDomain, '/');
        return $this->sDomain;
    }
214904
public function getHost() : string
    {
        $host = null;

        if ($this->isUsingTrustedProxy() && $this->headers->has(self::$trustedHeaderNames[RequestHeaders::CLIENT_HOST])) {
            $hosts = explode(',', $this->headers->get(self::$trustedHeaderNames[RequestHeaders::CLIENT_HOST]));
            $host = trim(end($hosts));
        }

        if ($host === null) {
            $host = $this->headers->get('HOST');
        }

        if ($host === null) {
            $host = $this->server->get('SERVER_NAME');
        }

        if ($host === null) {
            // Return an empty string by default so we can do string operations on it later
            $host = $this->server->get('SERVER_ADDR', '');
        }

        // Remove the port number
        $host = strtolower(preg_replace("/:\d+$/", '', trim($host)));

        // Check for forbidden characters
        // Credit: Symfony HTTPFoundation
        if (!empty($host) && !empty(preg_replace("/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/", '', $host))) {
            throw new InvalidArgumentException("Invalid host \"$host\"");
        }

        return $host;
    }
340050
public function getHost()
    {
        if ($this->initialized) {
            $hostname = $this->getHostName();

            if (($this->secure && $this->port != self::HTTPS_PORT) ||
                 (!$this->secure && $this->port != self::HTTP_PORT)) {
                $hostname .= ':'.$this->port;
            }

            return $hostname;
        }

        throw new BadMethodCallException('Connection not initialized');
    }
1263045
public function domain() {
      $host = $this->httpHost();
      $protocol = $this->protocol();

      $domain = $protocol . '://' . $host;

      return $domain;
    }
1010487
public static function domain() {
        if (is_cli()) {
            return L_URL;
        }
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        return defined('RUN_MODE') && RUN_MODE != 'HTTP' ? ''
        : trim($protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']), '/\\');
    }
31019
public function getHostName()
    {
        $remoteAddress = $this->server()->remoteAddress();

        $host = $this->server()->serverName();
        $fwdHost = $this->server()->get($this->getTrustedHeaders()['client_host']);
        if ($fwdHost && $fwdHost != '' && in_array($remoteAddress, $this->getTrustedProxies())) {
            $host = $fwdHost;
        }

        return strtolower($host);
    }
970304
public function getDomain()
    {
        if($this->getScheme() && $this->getHost()) {
            return $this->getScheme() . '://' . $this->getHost();
        }

        return false;
    }
445937
public function applicationWeb()
    {
        $config = $this->getConfigArray();
        $this->includeYii();
        $mergedConfig = ArrayHelper::merge($config, ['bootstrap' => ['luya\web\Bootstrap']]);
        $this->app = new WebApplication($mergedConfig);
        if (!$this->mockOnly) {
            return $this->app->run();
        }
    }
402177
private function updateHostHeader() : Request
    {
        $host = $this->host;
        $standardPort = $this->isSecure ? 443 : 80;

        if ($this->port !== $standardPort) {
            $host .= ':' . $this->port;
        }

        return $this->setHeader('Host', $host);
    }
97513
public function redirectForTrailingSlash()
    {
        $config = \Nf\Registry::get('config');
        $redirectionUrl = false;
        $requestParams = '';
        $requestPage = '/' . $this->_uri;
        
        // we don't redirect for the home page...
        if ($requestPage != '/' && mb_strpos($requestPage, '/?') !== 0) {
            // the url without the params is :
            if (mb_strpos($requestPage, '?') !== false) {
                $requestParams = mb_substr($requestPage, mb_strpos($requestPage, '?'), mb_strlen($requestPage) - mb_strpos($requestPage, '?'));
                $requestPage = mb_substr($requestPage, 0, mb_strpos($requestPage, '?'));
            }
            
            if (isset($config->trailingSlash->needed) && $config->trailingSlash->needed == true) {
                if (mb_substr($requestPage, - 1, 1) != '/') {
                    $redirectionUrl = 'http://' . $_SERVER['HTTP_HOST'] . $requestPage . '/' . $requestParams;
                }
            } else {
                if (mb_substr($requestPage, - 1, 1) == '/') {
                    $redirectionUrl = 'http://' . $_SERVER['HTTP_HOST'] . rtrim($requestPage, '/') . $requestParams;
                }
            }
            
            if ($redirectionUrl !== false) {
                $response = new \Nf\Front\Response\Http();
                $response->redirect($redirectionUrl, 301);
                $response->sendHeaders();
                return true;
            }
        }
        
        return false;
    }
48834
private function redirect()
    {
        if ($this->config['sandbox']) {
            $this->endpoint_redirect = $this->sandbox_endpoint_redirect;
        }
        $key1 = $this->config['app_key1'];
        $key2 = $this->config['app_key2'];
        $param = array(
            'AuthCode' => $this->auth_code,
            'facId'    => $this->config['app_id'],
            'facMemId' => $this->parameter['userId'],
            'hash'     => hash('sha256',
                "{$key1}{$this->auth_code}{$this->config['app_id']}{$this->parameter['userId']}{$key2}")
        );
        $this->endpoint_redirect .= '?' . http_build_query($param);
        header('Location:' . $this->endpoint_redirect);
        exit();
    }