Changing 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. However, in Drupal 8 and 9, the $base_url setting is deprecated and no longer used. Instead, you must update the base URL directly in the Drupal database. On ruachost.com, this ensures your site points to the correct domain after migration or rebranding.
Why Change the Base URL?
Section titled “Why Change the Base URL?”- Update your site after moving to a new domain.
- Ensure consistency across all internal links.
- Fix issues after migration or staging site deployment.
Steps to Change the Base URL in Drupal 8 and 9
Section titled “Steps to Change the Base URL in Drupal 8 and 9”Step 1: Export the Database
Section titled “Step 1: Export the Database”- Log in to your hosting account at ruachost.com.
- Use phpMyAdmin or the command line to export your Drupal database.
- Save the exported
.sqlfile to your local computer.
Step 2: Modify the Base URL
Section titled “Step 2: Modify the Base URL”- Open the exported
.sqlfile in a text editor. - Find all instances of the old URL.
- Replace them with the new URL.
- Save the changes.
Step 3: Import the Modified Database
Section titled “Step 3: Import the Modified Database”- Upload the modified
.sqlfile back to your hosting account. - Use phpMyAdmin or the command line to import the updated database.
Step 4: Test the Site
Section titled “Step 4: Test the Site”- Open your Drupal site in a browser.
- Verify that all links and resources load correctly.
- Confirm that the new base URL is applied consistently.
Important Notes
Section titled “Important Notes”- Always back up your database before making changes.
- Use search and replace carefully to avoid breaking serialized data.
- Test thoroughly after importing the modified database.