How To Change Admin URL in Magento

April 22, 2021


The default Magento Admin URL,, is an easy target for automated brute force and DDoS attacks. Reduce the attack surface by setting up a custom Admin URL and protect your Magento store.

Use one of these straightforward methods to change the Magento Admin URL:

  1. Edit the URL using the Admin Panel.
  2. Modify the Admin URL within the env.php file.
  3. Change the URL using the command line.

Find out how to change the Magento Admin URL and reduce malicious activity on your ecommerce store.

Admin changing setting in Magento.

Method 1: Change Magento Admin URL via Admin Panel

To change the default Magento Admin URL and path:

1. Access the Magento Admin panel.

2. Click Stores on the Admin sidebar.

3. Select Configuration in the Settings menu.

Access Configuration menu in Magento Admin.

4. Open the Advanced drop-down and click Admin.

Open Advanced option in Magento Admin.

5. Expand the Admin Base URL section.

6. Uncheck the Use System Value box and set the Use Custom Admin URL field to Yes.

7. Enter a custom URL in the Custom Admin URL field. Uncheck the Use System Value box if necessary.

Add a custom Magento Admin URL.

The Admin URL needs to end with a forward slash (/) and be in the same directory as the Magento storefront. For example,

Note: Ensure that any URL changes are consistent with the configuration in other dependent systems. For example, a hosting provider may require specific URL formats to be compatible with firewall settings.

9. Change the value in the Use Custom Admin Path field to Yes.

10. Enter a Custom Admin Path. In this example, the Admin path value is jw1gl4fwy. The complete URL to access the Magento Admin would be

11. Click Save Config.

Add custom Admin path in Magento Admin.

Log out of the Admin and log in using the new URL.

Method 2: Change Admin URL in the env.php File

Use the following steps to edit the Magento Admin path within the env.php file:

1. Establish an SSH connection with your Magento server.

2. Access the /app/etc/ subdirectory in the Magento installation directory:

cd /var/www/html/magento2.4/app/etc/
Location of the app/etc subdirectory in the Magento root directory.

In this example, Magento is installed in the /var/www/html/magento2.4/ directory. Edit the path to match the path on your server.

3. Open the env.php file using a text editor. For example, the nano text editor:

sudo nano env.php
Open etc.php in Magento using command line.

4. Locate the default value of the frontName parameter in the env.php file:

Location of the frontName value in the etc.php file.

5. Use lowercase letters to enter a custom value for the frontName parameter:

Custom frontName value in etc.php file.

6. Save the file and exit.

7. Access the Magento installation directory and flush the cache:

php bin/magento cache:flush
Clear Magento cache from command line.

Alternatively, use the Admin panel to flush the Magento cache.

Method 3: Change Admin URL from the Command Line

To change the Magento Admin URL using the command line:

1. Log in to the Magento server.

2. Access the Magento installation directory:

cd /var/www/html/magento2.4/

Modify the command to match the directory path on your system.

3. Use the following command to change the Magento Admin path:

php bin/magento setup:config:set --backend-frontname="new_admin_path" 

Enter your custom path instead of the new_admin_path value from the example.

ChangeMagento Admin path from command line.

If the system asks to confirm the change of the current configuration, enter Y to continue.

4. Flush the Magento cache:

php bin/magento cache:flush

Access the Magento Admin using the custom URL.

Restore Default Magento Admin URL

It is not uncommon to make a mistake while changing the Magento Admin URL. A faulty URL can lock users out of the Admin panel. To resolve this issue, utilize the command line and restore the default Magento Admin URL.

1. Access the Magento root directory and check the current Admin path value:

bin/magento info:adminuri

The system shows the current Admin path.

Display the current Admin URI.

2. Use the following command to restore the default Admin URL:

php bin/magento config:set admin/url/use_custom 0

3. If you changed the path within the env.php file or from the command line, reset the Admin path by entering:

php bin/magento config:set admin/url/use_custom_path 0 

The "Value was saved" message confirms that the path is reset to the default value.

Message shows that the default Magento URL is restored.

4. Flush the Magento cache before attempting to log in.

php bin/magento cache:flush


You have successfully changed the Magento Admin URL and established a new security layer for your Magento store.

Changing the Admin URL does not protect the online store from some of the more advanced ecommerce security threats. Make your store safer by applying a broader set of best ecommerce security practices.

About the author
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at CCBill. He has more than 8 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His engaging writing style provides practical advice and aims to spark curiosity for innovative technologies.
Talk to a Merchant Support Specialist