Magento 2 tutorials

How to change base URLs in Magento 2 (4 methods)

Pinterest LinkedIn Tumblr

There are many reasons why you need to change store URLs. For examples: Moving from localhost to live site, changing new website’s domain, moving from HTTP to HTTPS, or changing subdomain <=> domain…

In this tutorial, 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)

There are several ways to changes base URLs of your Magento 2 website.

Method 1: Changing base URL via Dashboard

Magento 2 allows users to change store’s base URL via backend dashboard. To do that follow these step:

Step 1: Login to admin and go to Store => Configuration => Web

change baseurl via dashboard

Step 2: Expand Base URL section and insert your desired new base URL, for example:

change base url

Remember to put a slash (/) at the end of the URL so that it can be extended with additional URL Keys.

Step 3: Save changes and go to Base URL (secure) section

The different between Base URL and Base URL (secure) is that if you plan to run your store in HTTPS you need to configure Base URL (Secure)

I strongly recommend running Magento 2 in HTTPS because it will make your store look secured and trusted. Also, you need https for further online payment configuration.

You can purchase an SSL certificate from SSL providers like Comodo, or use free SSL by Let’s Encrypt – the nonprofit Internet Security Research Group (ISRG).

In this section, input your Secure Base URL (same with base URL but use HTTPs instead of HTTP)

change base url secure

If you want to force using HTTPS on storefront, select Yes in Use secure urls on storefront and Enable HTTP Strict Transport Security (HSTS)

use secure urls on storefront

use secure urls on storefront

If you want to use HTTPS for Admin URL as well, select YES in Use Secure URLs in Admin. (If you select this option, you will need to use https url in order to access Magento 2 admin section)

url secure in admin

Finally, click save config to apply change. Clear cache and reload your website to see if base URL is changed.

Method 2: PHPmyadmin

Personally, I prefer this method because it works directly with Magento 2 database

Step 1: Open Phpmyadmin and login with your Magento 2 database credentials (in case you forget the login credentials, open app/etc/env.php file to retrive.

For example:

'dbname' => 'magento',
'username' => 'magento',
'password' => 'password',

Then the login for phpmyadmin is: magento / password

Step 2: Select the database associate with your Magento 2 website and search for table core_config_data, find the following lines:

  • web/unsecure/base_url
  • web/secure/base_url

Click edit and change value to your new base URL (remember to put slash at the end of every URL and put https in web/secure/base_url)

edit table in phpmyadmin

Finally, click GO to save changes and clear cache to update URL

Quick tip: you can also excute SQL command directly in PHPMYADMIN to update baseurl, use this syntax:

UPDATE core_config_data SET value = 'http://yourmagento2website.com/' WHERE path LIKE 'web/unsecure/base_url';
UPDATE core_config_data SET value = 'https://yourmagento2website/' WHERE path LIKE 'web/secure/base_url';

Put these lines in SQL tab of the selected database in PHPMYADMIN as below
run command in phpmyadmin

Change http://yourmagento2website.com/ and https://yourmagento2website.com/ with your desired URL and click on GO to update.

Method 3: Command line

If you are familiar with SSH, you can use SSH to update URL with a few commands.

Step 1: Login to your server using SSH

Step 2: Access mysql using this command

mysql -u $database_user -p$password

Replace $database_user with your mysql user and $password with your database password

For example, if you have root account of mysql with password as: 123456

mysql -uroot -p123456

Step 3: access your Magento 2 website database using this line

use $database

With $database = your Magento 2 store’s database.

Sample output:

use database

Next, run these command to update base URL (same as the commands we use in PHPmyadmin)

 update core_config_data set value = ‘http://yourwebsite.com/‘ where path = ‘web/unsecure/base_url’;
update core_config_data set value = ‘https://yourwebsite.com/‘ where path = ‘web/secure/base_url’;

Method 4: Change baseurl using Magento 2 CLI command

Alternative, you can also change baseurl using Magento 2’s CLI command

Access to your server using SSH and change directory to Magento 2 root folder, for example you install Magento 2 website in /var/www/html

cd /var/www/html

Run the following Magento 2 command to update base url

php bin/magento setup:store-config:set --base-url="http://yourwebsite.com/"

Run the following Magento 2 command to update base url (secure)

php bin/magento setup:store-config:set --base-url-secure="https://yourwebsite.com/"

Remember to put a slash at the end of each URL

Finally, flush cache to update changes

php bin/magento cache:flush

Conclusion

All the methods I mentioned in this tutorial will bring the same results, choose the method that you feel most comforable with.

If you encounter any error during the process, please drop a line in comment section (with a screenshot if possible). I will try my best to help you resolve the issue

Hung Tran is the main editor of magentip.com, he loves to write about everything related to Magento 2

12 Comments

  1. Code Promo 1xbet Pour Aujourd’hui vous donne un code promo 1xBet bonus de bienvenue de 100% sur le depot initial, accessible aux joueurs africains, jusqu’a 130€ selon votre devise. Le bookmaker 1xBet, reconnu dans le secteur des paris sportifs, opere avec succes depuis plus de dix ans.

  2. Bonus D’inscription 1xbet donne un bonus inscription 1xBet aux nouveaux joueurs, vous aide a booster votre premier depot, avec des paris gratuits 1xBet inclus. Le bonus de bienvenue 1xbet est soumis a des regles specifiques, y compris les conditions de mise et l’utilisation des fonds du bonus. Nous vous recommandons de consulter les termes et conditions sur le site Web 1xBet.

  3. Code Promo 1xbet Congo vous donne un code promo 1xBet paris sportifs avec un bonus de 100% jusqu’a €130, en plus d’un bonus de €1950 sur le casino en ligne et 150 tours gratuits. En utilisant le code promotionnel vous beneficiez d’avantages comparables aux plus grands bookmakers comme 1xbet. Inserez le code promotionnel dans le champ prevu lors de l’inscription et recevez un bonus de bienvenue garanti. Disponible uniquement pour les nouveaux joueurs, ce qui augmente considerablement le montant de votre premier depot.

  4. Hi exceptional website! Does running a blog such
    as this take a massive amount work? I’ve very
    little knowledge of programming but I was hoping
    to start my own blog in the near future. Anyway, should you have any recommendations or techniques for new blog
    owners please share. I understand this is off subject but I just needed to
    ask. Kudos!

  5. Hi there are using WordPress for your site platform? I’m new to the
    blog world but I’m trying to get started and set up my
    own. Do you need any coding expertise to make your own blog?

    Any help would be greatly appreciated!

  6. La promotion d’inscription 1xBet propose en 2026 donne la possibilite aux parieurs d’obtenir un montant maximal de 100 €/$ lors du depot initial. La valeur exacte depend du pays de residence ainsi que de la devise utilisee. Si le site est bloque dans votre region, un VPN ou un miroir permet d’y acceder sans difficulte. Pour consulter plus de details, cliquez ici : https://vmv.ru/admin/inc/1xbet_promokod_pri_registracii.html

  7. Le bonus de bienvenue 1xBet est disponible jusqu’a 130 $ pour tous les nouveaux inscrits. Pour obtenir le bonus, il faut effectuer un depot minimum et suivre la procedure correcte. En cas d’erreur dans le code, le bonus ne sera pas accorde. Pour plus de details sur le code promo 1xBet aujourd’hui, consultez ce lien : https://pathsinc.org/media/pgs/code_promo_1xBet.html

Write A Comment