How to change the absolute path (base URL) in Drupal 8 and 9

This article describes how to change the absolute path (base URL) in Drupal 8 and 9.

In Drupal 7 and earlier versions, you could change the base URL by modifying the $base_url variable in the Sites/Default/Settings.php file. In Drupal 8 and later versions, however, the $base_url setting is deprecated and no longer used.

However, you can update the base URL directly in the Drupal database. The following steps demonstrate how to do this.

Step 1: Export the database

First, export the current Drupal database to a file and download the file to your local computer.

For information about how to export a MySQL database, please see this article.

Step 2: Change the base URL in the database

After you have a file of the exported Drupal database, you are ready to make the changes to the base URL. To do this, follow these steps:

  1. Using your preferred text editor, open the exported SQL file.
  2. Find all instances of the old URL, and replace them with the new URL.
  3. Save your changes to the exported SQL file.

Step 3: Import the modified database

Next, upload to your hosting account the database file that you modified in step 2, and then import it into the Drupal database.

For information about how to import a MySQL database, please see this article.

Step 4: Test the Drupal site

View the Drupal site in your web browser and make sure everything works as expected.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.