public function parseRequestedURL()
    {
        // This is the re-constructions of teh proper URL.
        // 1. Schema
        $url = $this->app->getConfig('atk/base_url', null);
        if (is_null($url)) {
            // Detect it
            $url = 'http';
            $https = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || $_SERVER['SERVER_PORT'] == 443;
            if ($https) {
                $url .= 's';
            }

            // 2. Continue building. We are adding hostname next and port.
            $url .= '://'.$_SERVER['SERVER_NAME'];
            //if($_SERVER["SERVER_PORT"]!="80")$url .= ":".$_SERVER['SERVER_PORT'];
            if (($_SERVER['SERVER_PORT'] == '80' && !$https) || ($_SERVER['SERVER_PORT'] == '443' && $https)) {
                ;
            } else {
                $url .= ':'.$_SERVER['SERVER_PORT'];
            }
        }

        // We have now arrived at base_url as defined
        $this->base_url = $url;

        // 3. Next we need a base_part of our URL. There are many different
        // variables and approaches we tried it, REDIRECT_URL_ROOT, REDIRECT_URL,
        // etc, however most reliable is $this->unix_dirname(SCRIPT_NAME)
        $path = $this->unix_dirname($_SERVER['SCRIPT_NAME']);
        if (substr($path, -1) != '/') {
            $path .= '/';
        }

        // We have now arrived at base_path as defined
        $this->base_path = $path;

        // 4. We now look at RequestURI and extract base_path from the beginning
        if (isset($_GET['page'])) {
            $page = $_GET['page'];
            $this->page = $page;
        } else {
            $request_uri = $this->getRequestURI();
            if (strpos($request_uri, $path) !== 0) {
                throw $this->exception('URL matching problem')
                    ->addMoreInfo('RequestURI', $request_uri)
                    ->addMoreInfo('BasePath', $path);
            }
            $page = substr($request_uri, strlen($path));
            if (!$page) {
                $page = 'index';
            }

            // Preserve actual page
            $this->page = $page;

            // Remove postfix from page if any
            $page = preg_replace('/\..*$/', '', $page);
            $page = preg_replace('/\/$/', '', $page);
            $page = str_replace('/', '_', $page);

            if (substr($page, -1) == '_') {
                $page = substr($page, 0, -1);
            }
        }

        if (strpos($page, '.') !== false) {
            throw $this->exception('Page may not contain periods (.)')
            ->addMoreInfo('page', $page);
        }

        // We have now arrived at the page as per specification.
        $this->app->page = str_replace('/', '_', $page);

        $this->template_filename = $this->app->page;
        if (substr($this->template_filename, -1) == '/') {
            $this->template_filename .= 'index';
        }
    }