Magento base url: Why and how to change it in Magento 2

Magento base url:

Sometimes we may not notice the URL of each website, however, this factor plays an important role in SEO of the website. That’s why many the store owners have to change the Magento base URL overtime for the purpose of SEO best practices. In this article, we will provide you 3 useful methods to change the Magento 2 base URL. Enjoy the quick tutorial with a few clicks!

There are many reasons why you need to change store URLs in Magento website. For example, you can use this method when you need to change the domain URL or when you need

  • Need to develop a staging site
  • Change the server setup
  • Want a development site
  • Need to have a subdomain site
  • Simply want to change the domain

In all these cases, follow the below method to change the base URL in Magento 2.  With the below method, the base URL can be changed easily and all the sub-URLs will be redirected with the new base URL. Besides, we will go through steps by steps how to properly change a Magento 2 website’s URL (without 404 error on admin or any pages)

Methods to change Magento base url

Methods 1:  Change The Magento 2 Base URL From The Backend

Configure the unsecure base URLs

  1. Go to your Magento 2 backend:  Stores > Settings > Configuration.
  2. On the left menu, under General section, you click Web.
  3. Expand Base URLs section. Enter the unsecure (http) Base URL for your Magento website. Remember to end the URL with a forward slash (“/”).
  4. Optionally If you don’t want to use a secure base URL for the Admin, do the following steps:
    a. Expand Base URLs (Secure) section.
    b. 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.
  5. After completing, click the Save Config button.

Configure the secure base URLs

If your domain has a valid security certificate, you can change the URLs for either the storefront and Admin—or both—to run over a secure (https) channel.

Magento base url

  1. In your Magento 2 backend, move to Stores > Settings > Configuration.
  2.  At the left menu, under General section, click Web.
  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 you plan to to run the entire storefront over a secure (https) channel, set Use Secure URLs on Storefront to Yes.
    • If you need to run the entire Admin over a secure (https) channel, set Use Secure URLs in Admin to Yes.
  4. When complete, you click the Save Config button.

Method 2: Change base URL using Magento 2 CLI command

Besides, you can also change base URL using Magento 2’s CLI command

  • Log in to your server using SSH and change directory to Magento 2 root folder, for instance, you install Magento 2 website in /var/www/html
cd /var/www/html
  • Use the following command to update base url
php bin/magento setup:store-config:set --base-url=""
  • Use the below command to update base url (secure)
php bin/magento setup:store-config:set --base-url-secure=""
  • Keep in mind to put a slash at the end of each URL
  • Finally, flush cache to update changes
php bin/magento cache:flush

Method 3: 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. Access your Magento hosting server via SSH
2. Run the following command

mysql -u $database_user -p $database_name

3. Enter the password when prompted
4. Run the below command to access the database, where the database is the name of the database

use database

5. Use 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 Magento base URLs, run the following commands

update core_config_data set value = '' where path = 'web/unsecure/base_url';
update core_config_data set value = '' where path = 'web/secure/base_url';

These are the  simply  3 methods to change Magento 2 Base URL. We hope this tutorial was useful for you.  If you have any troubles, please ask them in the comments below. And if you need our professional assistance, feel free to contact us at any time. For more useful Magento tutorials like this, keep reading the Magento section on our Blog

69 Total Views 2 Views Today