How to Change Base URL in Magento 2: A Complete Guide

Change Base URL in Magento 2
November 27, 2020
March 19, 2025

Change base URL in Magento 2 is an essential step for maintaining the functionality, security, and overall performance of your online store. The base URL acts as the foundation for your website’s structure, directing traffic, defining paths for secure and unsecure content, and enabling seamless user navigation.

Incorrectly configured base URLs can result in broken links, compromised security, and SEO ranking losses. Thus, understanding how and when to change the base URL is crucial for every Magento store owner.

Updating the base URL may be necessary in various scenarios such as migrating to a new domain, switching from HTTP to HTTPS for enhanced security, or updating your store’s configuration after a redesign. Failing to make these updates properly can lead to a range of issues, from user accessibility problems to lost search engine traffic.

Understanding the Base URL in Magento 2

The base URL in Magento 2 serves as the root address for your store, dictating the structure for all pages, assets, and media files. It is essential to have the correct base URL to ensure your store functions smoothly across the web. There are two main types of base URLs in Magento 2: secure and unsecure.

What is the Base URL in Magento 2?

The base URL is essentially the address that visitors use to access your store. It is the starting point for all URL paths, which Magento uses to build links for product pages, images, CSS files, and other media. Any misconfiguration of the base URL can cause accessibility and display issues across the site.

The Difference Between Secure and Unsecure Base URLs

Magento 2 distinguishes between two types of URLs:

  • Secure Base URL: This is used for HTTPS (SSL) connections, ensuring that the connection between your site and users is encrypted and secure.
  • Unsecure Base URL: This is used for non-encrypted HTTP connections, typically for public-facing content like images and stylesheets.

While both URLs are necessary for full functionality, it’s important to maintain the distinction to ensure secure transactions and improve user trust.

The Impact of the Base URL on Site Performance and SEO

Changing the base URL can affect a variety of factors, such as site speed, SEO rankings, and the user experience. A misconfigured URL can result in broken links or inaccessible pages, causing users to abandon your site. Additionally, search engines like Google track the URL structure to index pages, and an incorrect base URL can lead to issues with crawling and ranking.

Preparing to Change the Base URL

Before making any changes, it’s vital to ensure that your Magento store is properly prepared. A backup of your site ensures that you can recover it if anything goes wrong during the change process. Additionally, placing your store in maintenance mode prevents visitors from encountering errors during the update.

Backup Your Magento Store Before Making Changes

Always create a full backup of your Magento store, including both the database and the file system. This step ensures that in the event of an issue, you can quickly restore the site to its previous state without losing any data.

Ensure Your Website is in Maintenance Mode

When making major changes like updating the base URL, putting your site in maintenance mode prevents customers from encountering errors or viewing incomplete pages. You can easily activate maintenance mode from the Magento Admin panel or via the command line interface.

Verify the Domain Name Settings and SSL Configuration

Before changing the base URL, verify your domain name settings and ensure that your SSL certificate is properly installed and configured. Failure to do so may cause HTTPS-related issues or security warnings for your users.

Methods to Change the Base URL in Magento 2

There are multiple ways to change the base URL in Magento 2. Each method has its own advantages, depending on your access level and technical expertise.

Changing the Base URL via the Magento Admin Panel

A straightforward method to modify the base URL is by using the Magento Admin Panel. This method provides an easy interface for entering the new URL and saving changes without touching the code or database directly.

Updating the Base URL via the Database

For more advanced users, the database provides a direct way to change the base URL by modifying the settings in the core_config_data table. This method is especially useful for bulk updates or when the admin panel is inaccessible.

Modifying the Base URL Using the Command Line

Magento 2 also offers a command-line interface (CLI) that allows for quick URL changes. By using Magento’s built-in commands, you can easily update the base URL, particularly in a development or production environment.

Step-by-Step Guide to Change the Base URL in Magento 2

Changing the base URL involves several steps. Below is a detailed guide that explains each phase of the process.

Modifying the Base URL via the Admin Panel

In the Magento Admin Panel, navigate to the “Store” > “Configuration” menu. Under the “General” section, find “Web” and click “Base URL.” From here, you can enter the new URL for both secure and unsecure protocols.

How to Update the Secure and Unsecure URLs

Both the secure and unsecure base URLs should be updated simultaneously to avoid inconsistency. Magento allows for independent configurations for secure and unsecure URLs, but they should match to avoid mixed content errors.

Setting the Base URL in the System Configuration Settings

After entering the URLs, save your changes in the configuration section. Ensure that both the base URL and its secure counterpart are pointing to the correct addresses for optimal performance.

Testing and Verifying the Changes in the Admin Panel

Once the changes are made, test the site’s functionality from both the frontend and backend. Check for issues such as broken images, missing assets, or SSL certificate problems.

Changing the Base URL via the Command Line Interface

Magento’s CLI is a powerful tool for making changes directly from the command line.

How to Access the Command Line Interface in Magento 2

To access the command line, navigate to your Magento installation directory via SSH. You will need appropriate permissions to execute commands.

Running the Command to Update the Base URL

Magento provides a command to update the base URL directly. Use the following command:

php bin/magento config:set web/unsecure/base_url http://your-new-url.com
php bin/magento config:set web/secure/base_url https://your-new-url.com

Verifying the Changes via CLI

After running the commands, check the configuration file to verify the updates were successfully applied.

Changing the Base URL in the Magento Database

For advanced users, updating the base URL directly in the database can be a more efficient option.

Accessing Your Magento Database

Using a tool like phpMyAdmin or a database management system, you can access your Magento database.

Updating the URL Directly in the Core Config Table

Find the “core_config_data” table and locate the entries for “web/unsecure/base_url” and “web/secure/base_url.” Update these entries with the new base URL values.

The Risks and Benefits of Modifying the Base URL in the Database

While updating the database allows for precise control, it carries some risks. Incorrect updates can break your store, so it’s essential to proceed with caution.

Troubleshooting Common Base URL Issues in Magento 2

Changing the base URL often leads to several common issues that can disrupt site functionality. Grasping the solution to these issues is crucial.

How to Fix the “404 Not Found” Error After Changing the Base URL

The “404 Not Found” error typically occurs when the base URL is incorrectly set or when content isn’t properly linked to the new URL. Ensure all media and links are correctly routed after the update.

Resolving Mixed Content Errors (HTTP/HTTPS Issues)

When transitioning to HTTPS, mixed content errors may occur if non-secure resources (like images or scripts) are still linked over HTTP. These must be updated to HTTPS to resolve the issue.

Troubleshooting SSL and Certificate Issues Post URL Update

After changing the base URL, ensure that your SSL certificate is properly configured for both secure and unsecure URLs. Errors related to SSL certificates often stem from incorrect URL configurations.

Impact of Changing the Base URL on SEO

Changing your store’s base URL can have significant SEO implications. If done incorrectly, it can result in lost rankings or broken backlinks.

How Changing the Base URL Affects Your Site’s SEO Ranking

Search engines track your URL structure, and altering it without proper redirection can confuse crawlers, leading to a potential drop in rankings. It’s important to set up redirects to ensure that the old URLs point to the new ones.

Best Practices for SEO-Friendly URL Structures in Magento 2

Magento allows for extensive customization of URLs. To optimize SEO, use clean, descriptive URLs that are easy for both users and search engines to understand.

How to Redirect Old URLs to Prevent SEO Loss

301 redirects are vital when changing the base URL. They ensure that both users and search engines are directed to the correct new page, preserving existing SEO rankings.

Post-Change Testing and Validation

After updating the base URL, thorough testing is required to ensure that everything is functioning correctly.

Testing Your Magento 2 Store’s Frontend After the URL Change

Verify that all pages load correctly, assets such as images and CSS files are displaying, and there are no broken links on the frontend.

Verifying the Secure URL and Admin URLs Are Working Properly

Test both secure (HTTPS) and unsecure (HTTP) URLs to ensure they direct users to the correct page without errors or security warnings.

Checking for Broken Links and Redirect Issues

Use tools like Google Search Console or third-party link checkers to identify any broken links that may have resulted from the URL change.

Base URL Configuration for Multiple Store Views

If you operate multiple store views, managing base URLs becomes even more critical.

How to Set Different Base URLs for Each Store View

Magento allows different base URLs for each store view, which can be configured through the Admin Panel or via the database. This ensures that each store view operates on its unique domain.

Configuring Base URLs for Multi-Store Magento Setups

For Magento stores with several store views or languages, setting up different base URLs for each view helps in localization and ensures each store functions on its appropriate domain.

Handling Base URL Changes During Migration

When migrating your Magento store to a new server or domain, updating the base URL becomes necessary to maintain continuity and prevent broken links.

Why You Should Change the Base URL After Migrating Your Magento Store

After migrating your store to a new domain or hosting server, updating the base URL ensures that the site operates correctly on the new environment and avoids any URL inconsistencies.

Updating the Base URL During Domain Migration

When migrating to a new domain, make sure to update the base URL to reflect the new address and ensure proper redirects are in place.

Ensuring Proper Redirects and SEO Preservation Post-Migration

301 redirects are essential during migration to ensure that users and search engines are redirected to the new domain without losing any SEO value.

Best Practices for Managing Base URL Changes

Managing base URL changes is a critical part of store maintenance. Ensuring that changes are executed carefully and efficiently can improve site functionality and preserve SEO.

Keeping Your Base URL Simple and SEO-Friendly

Avoid complex or overly long URLs. Keep them concise and descriptive for optimal SEO and user experience.

Leveraging 301 redirects to maintain traffic flow

Set up 301 redirects to ensure that old URLs seamlessly direct visitors to the new ones, preserving traffic and SEO rankings.

Avoiding Common Pitfalls When Changing the Base URL

Common mistakes include failing to test the new URLs, overlooking redirects, and not configuring SSL certificates. Avoid these pitfalls to ensure a smooth transition.

Magento 2 Base URL Settings for Different Environments

Magento’s flexibility allows different base URLs to be set for different environments, such as development, staging, and production.

Managing Base URLs for Development, Staging, and Production Environments

Each environment should have its base URL to ensure proper deployment and testing without affecting the live site.

How to Set Base URLs for Local and Remote Environments

Ensure that local development and remote production environments are configured with appropriate base URLs to avoid conflicts and ensure smooth transitions.

Best Practices for Environment-Specific URL Configurations

Use environment-specific configuration settings to prevent errors when deploying from staging to production.

Security Considerations When Changing the Base URL

When changing the base URL, security must remain a priority.

How to Ensure Your New Base URL Is Secure (SSL/HTTPS)

Ensure that your site is properly configured with SSL to avoid security vulnerabilities and provide a safe experience for your visitors.

Addressing Security Vulnerabilities After Changing the Base URL

Monitor your site for potential vulnerabilities and configure your base URL to use HTTPS across the site to prevent man-in-the-middle attacks.

Ensuring Proper Permissions and Admin URL Security

Make sure your Magento admin URL is secure and that permissions are properly configured to protect your site from unauthorized access.

Advanced Base URL Configuration Options in Magento 2

Magento offers advanced options for customizing base URLs.

Customizing Your Base URL for SEO and Branding

Custom URLs allow you to further optimize your store for search engines and improve your brand identity.

Configuring Canonical URLs in Magento 2 for Optimal SEO

Canonical URLs help prevent duplicate content issues and are an important part of maintaining SEO integrity.

Using URL Rewrites for Advanced Base URL Control

Magento allows for the creation of URL rewrites, which are useful for implementing SEO-friendly URLs or redirecting users to new paths.

Managing Cache and Base URL Adjustments in Magento 2

Cache management plays a crucial role when updating the base URL.

The Importance of Flushing Cache After Updating the Base URL

Flushing the cache is necessary to ensure that the changes take effect across the site.

Steps to Clear Magento Cache and Reindex Store Data for Optimal Performanc

Clearing Magento’s cache and reindexing data helps ensure that the new URLs are reflected across the store.

How Cache Management Can Affect the Base URL Settings

Improper cache management can lead to outdated URLs being served to users. Always ensure that the cache is cleared after making URL changes.

How Base URL Changes Affect Magento 2 Extensions

Changing the base URL can impact third-party extensions, which may rely on hardcoded URL values.

Reviewing the Compatibility of Extensions with New Base URLs

Ensure that all extensions are compatible with the new base URL settings to avoid any potential issues or conflicts.

How to Check and Update URLs in Third-Party Extensions

Some extensions may require manual URL updates to ensure they continue to function correctly after the base URL change.

Resolving Extension Issues Post Base URL Change

If any extensions break after the URL change, review their settings or consult the extension provider for troubleshooting steps.

Final Thought

Changing the base URL in Magento 2 is an important and sometimes complex task, but it is essential for keeping your store functioning smoothly and securely. By following best practices and ensuring thorough testing, you can successfully update your base URL without affecting your store’s performance or SEO ranking. The key to success is planning, preparation, and vigilance post-update to ensure that your Magento store continues to deliver a flawless experience to both customers and search engines.

Related Posts