How to change your Magento 2.1.x 2.2.x Store URLs

[aMiSTACX Magento 2.1.x+] URL Recovery

Sometimes we just need to change our Magento store URLs. [Normally when we do something “D’OH” and need to recover our store.]

A very quick way that works on our Magento stacks are these simple steps from CLI:

The following Magento 2.x CLI commands will update the Magento base-url and the base-url-secure values.

Go to the Magento’s root directory:

cd /var/www/magento

Then type within the console:

sudo php bin/magento setup:store-config:set --base-url="http://{yourdomain}/"

Replacing http://{yourdomain}/ with your new base-url.

e.g http://example.com/

You may also want to change the base-url-secure URL:

sudo php bin/magento setup:store-config:set --base-url-secure="https://{yourdomain}/"

Note: both base-url and base-url-secure values must contain the URL’s scheme, http:// or https://, and a trailing slash /.

Then clear your Magento Store cache:

sudo php bin/magento cache:flush

Note: I left the permissions error in the console image to show you will need to elevate to sudo to make the required updates.


Hostname Reset/Update

Another reason we may need to change our Magento store URLs is if we installed our store using an IP address, and now we want to change to a DNS hostname.

The overall process is still exactly the same as the below video will show. The only addition would be to make sure the vhost server name is updated too! You should be using HTTPS for a production store, and if you are using Let’s Encrypt to get your cert, you’ll need to make sure your vhost is updated using the correct hostname.

Please refer to your aMiSTACX instructions to walk you through the process.

Leave a Reply