_url = $_SERVER["HTTP_HOST"]; return $this; } public function prepareUrl() { $subdomain = str_replace(self::SITE_HOST, "", $this->_url); $subdomain = substr($subdomain, 0, -1); $this->_subLen = strlen($subdomain); return $this; } public function getFile() { if ($this->_subLen != 0) { $url = "http://" . self::SITE_HOST . "/subdomain/" .$this->_subdomain. $_SERVER["REQUEST_URI"]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); if (strpos($res,"Error 404")) { header("HTTP/1.0 404 Not Found"); } echo $res; } else { header("Location: http://".self::SITE_HOST); } } } $redirector = new Redirector(); $redirector->getUrl()->prepareUrl()->getFile();