从子目录Index.php Codeigniter爆炸URL路径

I am having trouble getting the main url from my sub directory. It has it's own application folder and index.php

http://localhost/project/admin/

I need my function below some how to remove admin/ and only display http://localhost/project/

How am I able to explode it or something similar that will remove admin/ and just show parent url.

http://localhost/project/

if (isset($_SERVER['HTTP_HOST'])) {

    $catalog_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $catalog_url .= '://'. explode('/' . $catalog_url);
    $catalog_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

} 
else{
    // Back Up Url
    $base_url = 'http://localhost/';
}

define('CATALOG_URL', $catalog_url);

unset($catalog_url);

After thinking about it for a while I had to do this

if (isset($_SERVER['HTTP_HOST'])) {

    $catalog_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';    
    $catalog_url .= '://'. $_SERVER['HTTP_HOST'] . rtrim(rtrim(dirname($_SERVER['SCRIPT_NAME']), 'admin'), '/.\\'). '/';

    } else {

    // Back Up Url
    $base_url = 'http://localhost/';

}

define('CATALOG_URL', $catalog_url);

unset($catalog_url);