---
title: "Setting base URLs"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how to set base URLs in Drupal without breaking non-production environments. Discover best practices for configuring $base_url across development, staging, and production, ensuring seamless functionality on Cloud Platform."
image:
type: "page"
url: "/acquia-cloud-platform/setting-base-urls"
id: "6ee7933b-667d-43ac-a6ea-0403a270cd09"
---

This document contains information about setting base URLs without breaking non-production environments.

Important

The [current Drupal version](/service-offerings/guide/software-life-cycle#supported-drupal-version) does not support `$base_url`.

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 Cloud Platform, 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](/acquia-cloud-platform/develop-apps/env-variable) that is set by the Cloud Platform environment.

Note for multisite users

Multisite installations should set `$base_url` in a dynamic fashion, as outlined here. Setting the `$base_url` to an empty string disables caching and is not recommended.

Modify and use the following example code as necessary to fit your needs, and be sure to add your [Remote Administration environment](/acquia-cms/ra/environment) if your application has one:

    if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
       switch ($_ENV['AH_SITE_ENVIRONMENT'])
            {
            case 'dev': $base_url = 'http://dev.example.com';
                    break;
            case 'test': $base_url = 'http://test.example.com';
                     break;
            case 'prod': $base_url = 'http://www.example.com';
                    break;
             }
        }

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 = 'http://www.example.com';
        }

Note

If you set a custom `$base_url`, be aware that the variable should not contain a trailing slash and should always start with either `http://` or `https://`.