No image

How to change your Magento 2 Store URLs

Magento 2 URL Change

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 deployment stacks for Magento OSE are these simple steps from CLI:

The following Magento 2.x CLI commands will update the Magento base-url, base-url-secure, and reset admin access.

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="https://{yourdomain}/"

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

e.g https://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 /. If you are using https, make sure both are https.

sudo php bin/magento setup:config:set --backend-frontname="admin_#####"

Assuming defaults, replace the ##### with your unique frontname value found in the /magento/apt/ect/env.php file.

Note: Failure to reset the Admin frontname value could lead to 404s when attemtping to access the admin dashboard.

Then clear your Magento Store cache:

sudo php bin/magento cache:flush

And last, reset permissions to baseline:

sudo chown -R www-data:www-data /var/www/magento

If you are using Redis, flush Redis too:

sudo redis-cli flushall

 


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.