Magento 2 Change Base URL Through CLI and Database
Struggling with broken links and admin access issues? Magento 2 change base URL procedures often create problems when they go wrong.
In this article, we will explain the right way to change the base URL and address issues.
Is Your Magento Store URL Change
About to Break Everything?
Watch what happens when you change your base URL without proper preparation...
Stores break on
first URL change
Average downtime
from URL errors
To change URL
the right way
🚨 Don't let this happen to your store!
Keep reading to learn the safe way to change your Magento 2 base URL...
Key Takeaways
-
Base URL settings control your web address and how customers access your store.
-
Four methods change base URLs through the admin panel, database, prompts, and files.
-
Backup needs include saving your database and files before making changes.
-
Common problems include broken styles, missing images, and admin access issues.
-
Proper testing ensures your store is functioning and redirects customers.
What is the Base URL in Magento 2?
The base URL serves as the foundational web address. Magento uses to construct all links throughout your online store. This configuration setting indicates the location of your store on the internet. It also tells how customers and search engines can access it.
Key functions of the base URL include:
-
Generates all frontend links for product pages, categories, and CMS pages.
-
Creates back-end admin panel URLs for store management.
-
Constructs media URLs for Magento images, logos, and other assets.
-
Forms the foundation for SEO friendly URLs and sitemap generation.
-
Enables proper redirect functionality and canonical URL structure.
Types of Magento Base URLs on the Platform
Base URL Type | Primary Purpose | Use Cases |
---|---|---|
Unsecure Base URL | Handles standard web traffic for non-sensitive pages | Product browsing, category pages, CMS content, and general navigation |
Secure Base URL | Manages encrypted traffic for sensitive transactions | Checkout process, customer login, payment pages, account management |
Unsecure Base Link URL | Controls internal link generation for non-secure pages | Magento navigation menus, breadcrumbs, category links, and product URLs |
Secure Base Link URL | Determines link generation for secure page connections | Checkout navigation, secure area linking, encrypted page transitions |
Steps to Change the Base URL Via CLI & Tables
1. Via CLI
-
Open the CLI from your admin panel and enter the prompts:
bin/magento config:set web/unsecure/base\_url \[invalid url, do not cite\]
bin/magento config:set web/secure/base\_url \[invalid url, do not cite\]
2. Via Tables
-
Open the Magento 2 database and enter the following prompts:
UPDATE core\_config\_data SET value \= '\[invalid url, do not cite\]' WHERE path IN('web/secure/base\_url', 'web/unsecure/base\_url');
When Do You Need to Change the Magento Base URL?
1. Domain Migration Scenarios
-
Business owners need to change their store's domain name for various reasons. Companies rebrand and need a new domain that matches their updated identity. Organizations buy premium domain names to improve their online presence and trust.
-
Website owners also migrate domains when getting many sites into a single platform. They transfer ownership of existing Magento stores to new companies. These operate under different domain names.
2. Moving from Staging to Production
-
Developers create staging environments using temporary domains for testing. These staging sites use URLs like
staging.yourstore.com
during development. Teams test new features, extensions, and customizations on these temporary environments. -
Once testing completes, developers must update the base URL to point to the live domain. This transition ensures customers access the the correct public domain.
-
The staging-to-production migration also involves updating all internal links and configurations. It is to match the final website address.
3. HTTPS Implementation
-
Modern ecommerce needs secure connections. It protects customer data and maintains search engine rankings.
-
Store owners use SSL certificates to enable HTTPS encryption across their entire website. Google prioritizes secure websites in search results. It makes HTTPS essential for SEO performance.
-
Businesses must update their base URL configuration. It is when transitioning from HTTP to HTTPS protocols. This change affects both secure and unsecure URL settings throughout the installation. Payment processors and modern browsers also need HTTPS for safe transactions.
4. Subdirectory Changes
-
Some businesses install Magento in subdirectories from the start. Companies later decide to move their store to the root domain. It improves SEO and simplifies navigation. This migration needs to update the base URL to remove the subdirectory path.
-
Businesses sometimes need to move their store into a subdirectory. It is to accommodate other website content. Companies might add blogs, corporate pages, or other applications to their root domain.
5. Multi-Store Configurations
-
Businesses expand their operations by creating many store views. These are for countries, languages, or product lines.
-
Each store view often needs its domain or subdomain to serve customer segments. Companies might use domains like us.yourstore.com for customers in the United States. Or domains like uk.yourstore.com for British customers.
-
Multi-stores also occur when they operate separate brands under different domain names. These configurations need individual base URL settings for each store.
Common Base URL Issues in Magento 2 with Solutions
1. CSS/JS Loading Issues
-
Browsers fail to load stylesheets and JavaScript files. It is when the base URL changes that don't update all resource paths.
-
Your store appears broken with missing formatting and non-functional elements. The browser console displays 404 errors for CSS and JS files that point to the old domain paths.
-
Static content deployment often retains references to the previous URL configuration. Magento generates static file URLs using cached configuration data. It reflects the old base URL. Users see unstyled pages with broken layouts. It is because the browser cannot locate essential styling files.
2. Image Display Problems
-
Product images disappear from category pages and product listings after URL changes. Magento stores image paths in the database.
-
It uses absolute URLs that reference the previous domain configuration. Customers see broken image placeholders instead of actual product photos throughout the store.
-
Media files fail to load. It is because Magento constructs image URLs using the old base URL settings. Magento Logo images, banner graphics, and CMS content images display as broken links.
-
The media gallery becomes inaccessible in the admin panel. It occurs when image paths don't align with the new URL structure. Product catalogs lose visual appeal and functionality without proper image display.
3. Redirect Loops
-
Servers create infinite redirect cycles. These are when secure and unsecure URL configurations conflict with each other.
-
Browsers get trapped in endless loops trying to access pages. These keep redirecting between HTTP and HTTPS protocols. Customers cannot reach any store pages because their browsers timeout.
-
Magento triggers redirect loops when base URL settings don't match the actual server. Mixed SSL settings cause the store to redirect secure pages to unsecure URLs.
-
It then redirects back to secure URLs. Web servers interpret conflicting URL configurations as instructions. It redirects visitors between different protocol versions.
4. Admin Panel Access Issues
-
Store admins lose access to the Magento backend. This is when admin URLs don't update with the new base URL configuration. Login attempts fail because the admin panel tries to redirect to the old domain. Admins see "Page Not Found" errors or connection timeouts.
-
Cookie domain mismatches prevent successful admin sessions after URL changes. The browser cannot establish proper authentication cookies.
-
It occurs when the admin URL doesn't align with the new domain configuration. Admin users get logged out because session management fails with an incorrect URL.
FAQs
Summary
The Magento 2 change base URL task is carried out by stores for SEO strategies. This article covers two methods for changing the base URL, along with their common issues. Here is a recap:
-
Base URL controls all website links and functionality.
-
Four methods exist: admin panel, database, CLI, and configuration.
-
Clear the cache and test after changing URLs.
-
Common problems include broken CSS, images, and redirects.
-
Backup your store before making any URL changes.
Choose managed Magento hosting to change base URLs and enhance SEO strategies.