3 Ways to Change Magento 2 Admin URL to Custom Admin URL
The Magento Admin URL, also known as the Backend URL, provides administrators access to the Magento backend. Changing this URL is crucial for enhancing security by preventing unauthorized access and safeguarding sensitive data. This guide outlines three methods to modify the Magento 2 admin URL. It also highlights precautions to prevent cyber attacks.
Key Takeaways
-
Discover three ways to set a custom admin URL in Magento 2, ensuring enhanced security for your store's admin panel.
-
Understand why changing the default Magento 2 admin URL is essential to secure sensitive store data and defend against automated threats.
-
Learn how to change the admin URL in Magento store's backend while adhering to essential firewall protection rules.
-
Understand the necessary precautions to take before modifying the Admin URL.
What is an Admin URL In Magento?
The Admin URL denotes the specific web address utilized for accessing the administrative panel of a Magento 2 store. This particular URL serves as the gateway to the backend of the store, granting access to various administrative functionalities.
Here, you can view, edit, and manage various elements. These elements include order data, customer information, product catalog, store settings, and extensions.
When you initially install Magento 2, an admin URL is automatically generated, typically consisting of a randomized string. In a standard Magento installation, the admin URL follows a specific format.
For example, the Default Base URL appears as [http ://yourdomain.com/magento/](http: //yourdomain.com/magento/), while the Default Admin URL and Path are structured as [http ://yourdomain.com/magento/admin](http ://yourdomain.com/magento/admin).
Why Change the Magento 2 Admin URL
Default URLs, often in the format sitename.com/admin, are predictable targets for potential hackers. Changing your Magento Admin URL offers various advantages, including:
1. Reduced Predictability
Hackers frequently depend on automated tools for scanning websites for vulnerabilities. Customizing the admin URL disrupts automated attacks used by hackers. It makes it more challenging for them to identify the entry point.
2. Preventing Unauthorized Access
Modifying the Admin URL safeguards your store against brute-force attacks. It also prevents unauthorized access to a store’s backend using multiple usernames and passwords.
3. Protection of Sensitive Information
By creating a custom admin URL, you add a layer of protection to your store. This measure helps shield sensitive data and customer information from potential security breaches. It also reduces the risk of exposure to scripts attempting to break into your Magento site.
Prerequisites Before Changing Magento 2 Admin URL
-
Contact Your Hosting Provider: Check with your Magento hosting provider for any specific requirements or firewall rules related to the admin URL.
-
Test in a Development Environment: Prioritize making changes in a development environment to avoid potential disruptions on your live website.
-
Exercise Caution with Configuration Files: If you're not experienced in editing server configuration files, it's advisable to seek expert assistance. This precaution helps prevent accidental loss of access to the admin panel.
3 Ways to Change Magento 2 Admin URL
Method 1: Change Admin path from the command line (SSH)
To modify the Magento 2 Admin URL, you can use the command line through SSH. Follow these steps:
- Access your Magento 2 server using SSH with your credentials.
ssh your-username-ssh@server-ip
- Navigate to Magento 2 Directory. For example:
cd /home/cloudpanel/htdocs/www.domain.com/
- You can view your current Admin URL using the following command:
php bin/magento info:adminuri
Note- You can also use this command to view your updated URL.
- Run this command to configure the Magento 2 Admin URL as 'secureAdmin123'.
php7.4 bin/magento setup:config:set --backend-frontname='secureAdmin123'
Method 2: Change the Admin URL by editing the Env.php file
You can also change the Magento 2 backend URL by directly editing the app/etc/env.php
file instead of running the CLI command. Here’s how:
-
Go to the
app/etc/env/php
file in a text editor. -
Inside the file, locate the section with 'frontName' => 'admin,' and change the value within the quotes to your desired new admin URL.
-
For example, 'frontName' => 'admin' can be changed to 'frontName' => 'secureAdmin123'. It should look like this:
return [
'backend' => [
'frontName' => 'secureAdmin123'
],
Note- It replaces the value within the quotes from ‘admin’ to your new admin URL, for instance, ‘admin’ > ‘secureAdmin123’
-
To ensure the changes take effect, clear the Magento cache. You can do this by going to System> Tools> Cache Management and clicking Flush Magento Cache.
-
Return to your server and execute the following command to flush the cache.
php bin/Magento cache:flush
Method 3: Create a custom Admin URL from the Magento Admin Panel
-
Go to Magento Admin panel > Stores > Settings > Configuration.
-
In the left panel, locate and select the Admin within the Advanced category.
-
Expand the Admin Base URL to set up your custom URL
-
Choose Use Custom Admin URL and set it to Yes.
-
Next, enter your desired Custom Admin URL in this format:
http://yourdomain.com/magento/
. -
Set Custom Admin Path to Yes. Add your URL to the Custom Admin URL field ending with slash ‘/.’
-
Once you've configured these settings, click the Save Configuration button to apply all the changes.
-
Log out from your Magento account and then log in using the newly created custom URL.
Precautions Before Changing Your Magento Admin URL
1. Back-Up Your Website
Backing up involves duplicating all files and databases associated with your Magento store. You can simplify this process by using specialized backup tools or Magento-specific plugins.
This precautionary measure shields you from data loss or errors during the Admin URL modification process.
2. Update Extensions and Custom Code
Updating your extensions and custom code ensures smooth functionality with the new URL. Some extensions and custom code may contain hard-coded references to the old Admin URL.
To facilitate this process, check for updates from extension developers. You can also consult extension documentation for instructions on carrying out these updates.
3. Implement URL Redirects
After changing your Magento Admin URL, it's vital to set up Magento redirects from the old URLs to the new ones. It guarantees that anyone accessing the old URLs will be automatically directed to the new admin URL. It eliminates confusion and unauthorized access.
It also ensures a seamless transition and maintains a secure environment for your Magento storefront.
Note: Update any external links or bookmarks that may have previously referenced the old admin URL to align with the new configuration.
FAQs
1. What is the default Admin URL in Magento 2?
The default Admin URL in Magento 2 is automatically generated during the installation process. It typically comprises a random string following a specific format. This URL provides access to the backend, enabling administrative functionalities.
2. How can I change the default Admin URL in Magento 2?
To change the default URL, you have several methods available. You can alter the Admin URL via the command line using SSH by modifying the app/etc/env.php file or creating a custom URL within the Magento Admin panel. Each method offers a secure way to customize the Admin URL.
3. Why is it crucial to change Admin URL in Magento 2?
Changing the default Magento Admin URL is crucial to enhance security by preventing predictable attacks. Hackers often target default URLs, attempting brute-force attacks to gain unauthorized access. Customizing the Admin URL helps mitigate such risks.
4. How can I create an Admin URL that resists brute force attacks?
To create an Admin URL that resists brute force attacks, you need to know how to edit configuration files on the server. You can modify the 'frontName' value in the app/etc/env.php file using a text editor. This alteration changes the default URL to a custom, more secure one.
5. What precautions should a Magento developer take when changing the Admin URL?
When changing the Admin URL, precautions such as backing up the website and understanding how to edit configuration files on the server are vital. This measure ensures a safety net in case of errors. It also safeguards against accidental loss of access to the admin panel.
Summary
Changing your Magento Admin URL is a crucial step in enhancing the security of your online store. It helps protect sensitive information and prevents unauthorized access to the administrative panel of a Magento 2 store. The tutorial covered three methods to change the Magento 2 Admin URL. It includes command line modifications, editing the Env.php file, and creating a custom Admin URL. It also highlights the importance of precautions to prevent cyber attacks and complications.
Discover optimized Magento server hosting to enhance the security and efficiency of your online store.