- Go to the
App.php
file; - In section
public $baseURL = 'http://localhost:8080/';
, and replace with this script:
public $baseURL;
public function __construct()
{
if (!empty($_SERVER['HTTPS'])){
$root = "https://".$_SERVER['HTTP_HOST'];
$root .= dirname($_SERVER['SCRIPT_NAME']);
$this->baseURL = $root."/";
}else{
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= dirname($_SERVER['SCRIPT_NAME']);
$this->baseURL = $root."/";
}
}
- done, and good luck.
This really helped me out of the many ways I found to make the base url in codeigniter 4
dynamic.