Do you want to change Magento 2 Base URL?
The URL of the eCommerce store plays an important role in SEO. You must keep the base URL as clean as possible to follow the best Magento SEO practices.
All the websites have two types of base URL. One for the admin dashboard, and another for the frontend.
You can either keep these URLs secure or unsecure.
Secure means the page loads on the HTTPS, keeping the data safe. While HTTP is unsecure and without the SSL certificate.
Read more about the HTTP and HTTPS.
Google favours the secured sites while ranking in SERP.
#1 Change Magento 2 Base URL From The Backend
Go to your Magento 2 admin panel.
Navigate to the Stores > Settings > Configuration
Step 1: Look at the left Menu, see the General section and Click on the Web.
Left Menu > General Section > Web
Step 2: Click on the Magento 2 Base URL section to expand it.
Enter the Base URL of the store.
Note: Make sure that the URL ends with a forward slash.
Step 3: Save the Configuration.
If you want to make the Magento 2 Base URL secure, then you can follow these steps.
To configure the secure HTTPS for the storefront, add the secure base URL . (https instead of http)
- Enable the Storefront to Yes: The entire storefront will run on the secure https.
- Enable the Admin to Yes: The entine admin dashboard will run on https.
Save the configuration.
#2 Change Magento 2 Base URL By The Command Line
You can change the Magento 2 Base Url from the command line.
Follow these steps:
Step 1: Log in to your server via SSH
Step 2: Type the following command:
mysql -u $database_user -p $database_name
Enter the password.
Step 3: Write the following command. It will give you access to the database.
Put the name of the database at the place of the “database”.
use database
Step 4: Use the following command to display the current base_urls.
select * from core_config_data where path like '%base%url%';
Step 5: Run the following command to change the Magento 2 Base URL.
update core_config_data set value = 'http://example.com/' where path = 'web/unsecure/base_url';
update core_config_data set value = 'https://example.com/' where path = 'web/secure/base_url';
Also Read
- How to Install Magento 2.4 with Command Line?
- Magento 2 Commands: A Useful list for Magento Developers
- Magento 2 Requirements that You Must Take care of
- Magento 2.4 – Highlights
Final Words
I hope this tutorial helped you in changing the Magento 2 Base URL.
If there are any questions or any issues, then leave them in the comments.