>An Instant Guide to Change Base URLs in Magento 2

An Instant Guide to Change Base URLs in Magento 2

Sometimes we may not notice the URL of each website, however, this element plays a significant role in SEO. That’s why many marketers or merchants have to change the base URL overtime for the purpose of SEO best practices.

Just like any website, each Magento website is assigned a base URL that is used for the frontend and Admin. If you have a security certificate for your domain, you can configure each or both base URLs to operate over a securely encrypted SSL channel. For more details, unsecure base URLs begin with “http,” while secure base URLs begin with “https.”In this article, we will give you two methods to change the Magento 2 base url. Enjoy the quick tutorial with a few clicks!

Change the Magento 2 base URL from the backend

Configure the unsecure base URL

In your Magento 2 admin panel, access Stores > Settings > Configuration

  1. On the left menu, under General section, click on Web
  2. Expand Base URLs section. Enter the unsecure (http) Base URL for your store. Make sure to end the URL with a forward slash (“/”)
  3. (optional) If you don’t need a secure base URL for the backend, follow these steps:
  • Expand Base URLs (Secure) section
  • Enter your unsecure (http) base URL into Secure Base URL field.The URL should be the same in both the Base URLs and Base URLs (Secure) sections

4. Click the Save Config button

Notes:

  • To indicate a substitute location for the Base URL for Static View Files, enter the path starting with the following placeholder: {{unsecure_base_url}}
  • To specify a substitute location for the Base URL for User Media Files, enter the path starting with the following placeholder: {{unsecure_base_url}}
  • In case of a typical installation,you will not have to update the paths for the static view files or media files because they already take over the base URL

Configure the secure base URL

  1. If your domain has been assigne a valid security certificate, you can configure the URLs for both or either the storefront and Admin to run a secure (https) channel.In your Magento 2 backend, go to Stores > Settings > Configuration
  2. On the left menu, under General section, click Web

    Configure secure URLs in Magento 2
  3. Expand Base URLs (Secure) section. Then, do the following steps:
    • To use a secure (https) for the storefront, enter the Secure Base URL, followed by a forward slash (“/”).
    • If there is a need to run the entire storefront with a secure (https) channel, set Use Secure URLs on Storefront to Yes.
    • If there is a need to run the entire Admin with a secure (https) channel, set Use Secure URLs in Admin to Yes.
    • Click the Save Config button

Change the Magento 2 base URL by the command line

The following Magento 2’s CLI command will update the Magento base-url and the base-url-secure values.

1. Log in your Magento hosting server via SSH
2. Write in the following command

mysql -u $database_user -p $database_name

3. Enter the password when promted
4. Use the following command to access the database, where the database is the name of the database

use database

5. Run the following command. The current base_urls set in Magento will be displayed in here

select * from core_config_data where path like '%base%url%';

6. To modify the base URLs, enter the following commands

update core_config_data set value = 'http://example.com/' where path = 'web/unsecure/base_url';
update core_config_data set value = 'https://example.com/' where path = 'web/secure/base_url';

That’s all!
We hope that this tutorial fits you well! Also, if you have any question or sharing, don’t hesitate to write us in the comments below!
You can find many informative articles here and useful tutorials here. Stay curious with us!