How can we help you today?

How to change your Magento 2 base-URLs

Created by: Rens Zuurbier

Modified on: Fri, 29 May, 2020 at 8:48 AM


There are several ways to configure the base_url settings of your Magento 2 shop.

note: When you have an SSL certificate and use the secure base URL you should change the unsecure base URLs to HTTPS as well. This could result in conflicts when you leave this to HTTP.

TABLE OF CONTENTS

Configuring your base URL's over the web

Configure your base URL's in the Magento 2 admin

To configure your base URL's from within Magento 2, first login to your Magento admin area.

From the top navigation bar, select Stores -> Configuration:

From the configuration menu, select the GeneralWeb:

Open the secure and unsecure dropdown sections from the page:

Now, insert the correct URL configuration in the base url input box and click on Save Config.  After saving your adjusted base URL’s config, navigate to System -> Cache Management:

To clear your caches, click the big orange button at the top of the page:

Configure your base URL's using PHPmyAdmin

As changing the base URLs using PHPmyAdmin works the same for both Magento 1 and Magento 2, take a look at the Magento 1 article about changing base URLs.

Configuring your base URL's using SSH

Change base URL's settings with MySQL from the command line

To change your base URLs using plain MySQL queries, you can use exactly the same commands as described in the Magento 1 article.

Change your base_url using n98-magerun2

Changing your base URLs using n98-magerun2 on Magento 2 is yet not as easy as with Magento 2 as there are no plugins yet to provide this functionality.

Therefor we use the config:store:set functionality in n98-magerun2.

To do this, login on your Hypernode using SSH and navigate to your Magento 2 directory:

cd ~/magento2

Then, get an overview of the current base URL settings:

n98-magerun2 sys:store:config:base-url:list

This will print out a list of your storefronts and their URL configuration:

Magento Stores - Base URLs
 
+----+---------+------------------------------+------------------------------+
| id | code | unsecure_baseurl | secure_baseurl |
+----+---------+------------------------------+------------------------------+
| 1 | default | http://support.hypernode.io/ | http://support.hypernode.io/ |
+----+---------+------------------------------+------------------------------+

Next run magerun2 and set the base URLs:

cd /data/web/magento2
export SHOPHOST="mynode.hypernode.io"
magerun2 --root-dir=/data/web/magento2 config:store:set web/unsecure/base_url http://$SHOPHOST/
magerun2 --root-dir=/data/web/magento2 config:store:set web/secure/base_url https://$SHOPHOST/
magerun2 --root-dir=/data/web/magento2 config:store:set web/unsecure/base_link_url https://$SHOPHOST/ 
magerun2 --root-dir=/data/web/magento2 config:store:set web/secure/base_link_url https://$SHOPHOST/
magerun2 --root-dir=/data/web/magento2 cache:flush

Keep in mind:

  • Make sure the base-urls are always ending with a trailing slash (`/`)
  • Replace the url for SHOPHOST with the url of you shop.

Change the base URLs to SSL using a script

If you want to change your base URL for use with SSL, we created a handy python script that you can use to quickly adjust your base URLs to use SSL. To make use of this script, setting the unsecure base URL first is required.

To use it, download the script, make it executable and run it:

cd /data/web/public
wget https://gist.githubusercontent.com/hn-support/0c76ebb5615a5be789997db2ae40bcdd/raw -O change-baseurls.py
chmod +x change-baseurls.py
./change-baseurls.py

Now check your base URLs using Magerun:

n98-magerun2 sys:store:config:base-url:list
R
Rens is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.