I need to set dynamic base url in codeigniter due to few following reasons.
Also you can try this.
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://". @$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;
I just need to share my knowledge, since I already found the answer as mention below.
Just overwrite the line in config/config.php with the following:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
If you are using the sub folder you can use following code:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With