Magento 2 Tutorials

How to Change Magento Admin URL

magento admin panel url

Magento is one of the most widely used ecommerce platforms out there. The CMS  is recognized for its security as well as it is the most secure among many platforms for ecommerce stores.

While there are many practices recommended for the security of Magento stores, one highly useful practice is to use a unique path for Magento admin panel URL rather than using the default URL.

In this tutorial, I will teach you how to change Magento admin URL. I will show you multiple methods for changing the admin panel URL for both Magento 1.x and Magento 2.x.

Change Magento Admin Panel URLChange Magento 2 Admin Panel URL
Through the Admin PanelThrough the Admin Panel
By Editing local.xml file By Editing the env.php
Via a Command Line


Change Magento Admin Panel 

Method 1: Through the Admin Panel

The first step towards changing Magento admin URL is to go to the admin panel of your Magento store and then navigate to SYSTEM → Configuration:

system-config magento admin url
Now scroll down and click on Admin option under the ADVANCED tab:

advanced-admin magentoNow unfold Admin Base URL section and select Yes from Use Custom Admin Path drop-down menu and enter the admin path of your choice. I am using Magento, you can change it according to your requirements:

Note: Don’t change Use Custom Admin URL option to Yes.

admin base url magento
Next, just click on Save Config button:
save config admin url magento

Method 2: By Editing local.xml file

Open the local.xml file in the text editor via the app/etc directory from the root directory of your Magento store. Here you will search for this code:

<admin>
        <routers>
            <adminhtml>
                <args>
                    <frontName><![CDATA[admin]]></frontName>
                </args>
            </adminhtml>
        </routers>
    </admin>

In the above code the Magento admin URL is set as admin, thus changing it to magento gives:

 <admin>
        <routers>
            <adminhtml>
                <args>
                    <frontName><![CDATA[magento]]></frontName>
                </args>
            </adminhtml>
        </routers>
    </admin>

You can use any of the above methods to change Magento Admin URL. Last but not least, don’t forget to clear the cache by navigating to System → Cache Management from the admin panel of your Magento store. Now let’s move to the methods for changing Magento 2 Admin URL.

Change Magento 2 Admin Panel URL

Method 1: Through the Admin Panel

Open the Admin panel of your store and navigate to STORES → Configuration

stores - config magento 2 recaptcha

Scroll down and click on Admin under ADVANCED.

Now unfold the Admin Base URL section and make the changes in the same way as I have taught you for Magento 1.x:

Then, just click on Save Config:
save config 2FA

Method 2: By Editing env.php

Open the env.php file in the text editor via app/etc directory from the root directory of your store. Now, you will see the following code:

<?php

return array (
 'backend' =>
 array (
   'frontName' => 'magento',
 )

Replace the above code with the following one to change Magento 2 Admin URL from admin to magento:

 'backend' =>
  array (
    'frontName' => 'magento',
  ),

Method 3: Via a Command Line

Connect your store with an SSH terminal and go to the root directory of your Magento 2 store. Now just run the following command:

php bin/magento setup:config:set –backend-frontname=”magento”

In the command above, I have set the admin URL path as magento, and you can set it according to your desire.

I have mentioned and elaborated three methods for changing Magento 2 Admin URL. After using the method of your choice, you have to clean the cache. To do that, run the following commands in the Magento 2 root directory

rm -rf var/cache/*
php bin/magento cache:clean
php bin/magento cache:flush

Wrapping Up

Every ecommerce store must have a secure admin URL. After following this tutorial, you should now be able to change the Magento Admin URL. If you still have any confusion or want to discuss anything, feel free to use the comment box below!

Also if you are looking to enable URL rewrite in Magento 2 see: How to Enable URL Rewrite in Magento 2

Frequently Asked Questions

Q1. Magento Admin URL not found on server: Why?

You may be facing this issue because you are entering a wrong Magento Admin Panel URL. This can easily be corrected. For Magento 1.x, go to local.xml from app/etc directory and for Magento 2.x, go to env.php from app/etc directory.

Q2. Why does Magento Admin URL still opens the old URL?

It’s because you may have not cleared the cache of your store. Clear and flush it, then try opening your Magento admin panel URL.

Subscribe Newsletter

Subscribe to get latest Magento news

40% Off for 4 Months on Magento Hosting + 30 Free Migration