CodeIgniter multi base_url

As I wrote in the previous post, the problem with defining the base_url variable is quite annoying. Specifically, this variable takes care of creating the path to the links, the action in the forms, redirects and so on and if it is not the last CI does not work correctly 🙂 It works but does some crazy things with urls 🙂 The solution as always is simple ( it appeared for me shortly before I decided to write it myself) 😀

$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

This piece of code replaces base_url in the configuration file. Works as seen for both http and https. It only takes the folder in which the platform is located like this, that no intervention is needed on our part.

Leave a Reply

Your email address will not be published.

Anti SPAM *