paulopmx - 05 September 2007 09:19 AM
Don’t you just hate it, when you move from development server to production server that you have to change the $config[’base_url’] setting?
Well I do. Because I do it a lot, specially when I’m demoing a web application, that’s why I added this code to the config.php
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
Once thats added, Codeigniter base_url will adapt to whatever the url you’re using.
My suggestion:
index.php (the main file of your CI application) :
$_ciroot = rtrim(dirname(__FILE__),"/")."/";
if (stristr(PHP_OS, 'WIN')) $_ciroot = str_replace("\\", "/", $_ciroot);
$_ciroot = str_replace($_SERVER['DOCUMENT_ROOT'], '', $_ciroot);
define('CIROOT', $_ciroot );
config.php:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'].CIROOT;
...you can improve the protocol detection.
BR!