Merge pull request #2981 from vlakoff/base_url
Work on determination of "base_url" config item
diff --git a/system/core/Config.php b/system/core/Config.php
index f630d17..ad0e5f9 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -78,9 +78,9 @@
{
if (isset($_SERVER['HTTP_HOST']))
{
- $base_url = is_https() ? 'https' : 'http';
- $base_url .= '://'.$_SERVER['HTTP_HOST']
- .str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
+ $base_url = (is_https() ? 'https' : 'http')
+ .'://'.$_SERVER['HTTP_HOST']
+ .substr($_SERVER['SCRIPT_NAME'], 0, -strlen(basename($_SERVER['SCRIPT_NAME'])));
}
else
{
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index 6a0a7a3..2c28a63 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -81,7 +81,7 @@
// Setup server vars for detection
$host = 'test.com';
- $path = '/path/';
+ $path = '/';
$script = 'base_test.php';
$_SERVER['HTTP_HOST'] = $host;
$_SERVER['SCRIPT_NAME'] = $path.$script;
@@ -89,7 +89,15 @@
// Rerun constructor
$this->config = new $cls;
- // Test plain detected
+ // Test plain detected (root)
+ $this->assertEquals('http://'.$host.$path, $this->config->base_url());
+
+ // Rerun constructor
+ $path = '/path/';
+ $_SERVER['SCRIPT_NAME'] = $path.$script;
+ $this->config = new $cls;
+
+ // Test plain detected (subfolder)
$this->assertEquals('http://'.$host.$path, $this->config->base_url());
// Rerun constructor