Welcome Guest, Not a member yet? Register   Sign In
base_url() wrong even when explicitly set
#1

[eluser]madshadow[/eluser]
I have multiple environments set up for my application (development, staging, demo, production). Everything was working smoothly among the environments until I made some kind of change to enact more dynamic environment setting. The strange thing is that it works fine on my localhost and demo server, but not on staging when I am at staging.domain.com.

To debug, my main landing page echoes out the ENVIRONMENT variable (which correctly shows 'staging') and then I echo out base_url which incorrectly shows (http://localhost/domain). For some reason this is only happening on staging and not on demo or localhost. I even tried removing the dynamic base_url generation and hard-coded "staging.domain.com" but it is still showing as "localhost/domain" - I am sure this is something stupid I am missing but I have been beating my head over this. Does anyone see what I'm missing? Any help would be greatly appreciated. Thank you in advance

I have the following in my index.php file to set the environment variable:

Code:
if (isset($_SERVER['PLATFORM']))
{
    switch ($_SERVER['PLATFORM']) {

        case 'PAGODA':
            define('ENVIRONMENT', 'demo');
        break;
    // add additional cases for more environments
    }
}
else
{
    if (strpos($_SERVER['SERVER_NAME'], 'local') !== FALSE)
{
   define('ENVIRONMENT', 'development');
}
elseif (strpos($_SERVER['SERVER_NAME'], 'staging.') === 0)
{
   define('ENVIRONMENT', 'staging');
}
elseif (strpos($_SERVER['SERVER_NAME'], 'demo.') === 0)
{
   define('ENVIRONMENT', 'demo');
}
else
{
   define('ENVIRONMENT', 'production');
}
}

I have the following to set the url in my config.php file (actual domain name redacted):

Code:
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
  case 'development':
   $config['base_url'] = "http://localhost/domain/";
  break;

  case 'staging':
   $config['base_url'] = "http://staging.domain.com";
  break;
  
  case 'production':
   $config['base_url'] = "http://www.domain.com/";
  break;

  case 'demo':
   $config['base_url'] = "http://demo.domain.com/";
  break;

  default:
   $config['base_url'] = "http://www.domain.com/";
  
}
}
else
{
$config['base_url'] = "http://www.domain.com/";

}

Finally, if it matters, I have the following in .htaccess file:

Code:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]


Messages In This Thread
base_url() wrong even when explicitly set - by El Forum - 05-15-2012, 07:22 AM
base_url() wrong even when explicitly set - by El Forum - 05-15-2012, 07:52 AM
base_url() wrong even when explicitly set - by El Forum - 05-15-2012, 09:18 AM
base_url() wrong even when explicitly set - by El Forum - 05-15-2012, 11:53 AM
base_url() wrong even when explicitly set - by El Forum - 05-15-2012, 12:10 PM
base_url() wrong even when explicitly set - by El Forum - 05-15-2012, 12:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB