Setting $base_url without breaking the Development and Staging environments

Occasionally, it may be necessary to set the $base_url value in a Drupal application's settings.php file, because a contributed module may require this variable to be set, or an application may have specialized configurations.

Unfortunately, setting this variable can cause issues on Acquia Cloud, where there are separate Development, Staging, and Production environments. If it is set unconditionally, the $base_url variable instructs Drupal to rewrite all requests for all environments, which breaks environments to which this variable doesn't point.

The solution is to make use of the $_ENV['AH_SITE_ENVIRONMENT'] environment variable that is set by the Acquia Cloud environment.

Modify and use the following example code as necessary to fit your needs, and be sure to add your Remote Administration environment if your application has one:

if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
  switch ($_ENV['AH_SITE_ENVIRONMENT']) 
    case 'dev': $base_url = '';
    case 'test': $base_url = ''; 
    case 'prod': $base_url = '';

You can further modify the preceding code if there are environments that don't require $base_url to be explicitly set. For example, if the $base_url variable is required only for Production, you can use the following much shorter code snippet:

if (isset($_ENV['AH_SITE_ENVIRONMENT']) && $_ENV['AH_SITE_ENVIRONMENT'] === 'prod') {
$base_url = '';

Contact supportStill need assistance? Contact Acquia Support