bhogg - 24 April 2008 12:09 PM
I neglected to add the last line in the code, though it could probably be pieced together from the previous posts:
$proto = "http" .
((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$server .= '/';
if (strstr($server, 'localhost'))
$server .= 'subdirectory/';
$config['base_url'] = $proto . $server;
As already said, this would return only the base http://www.domain.com/ or http://www.domain.com/subdirectory/ depending on what you specify for “$server .= ‘subdirectory/’ when testing on localhost.
The main advantage we’ve got now is the handling of http/https, you’ll still need to update your subdirectory for each project’s config.php file…
But my original contribution already handles subdirectory, maybe you can just combine the two, where you handle the protocol.
$proto = "http" .
((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$server .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);