>3 Easy Ways To Change Admin URL in Magento 2

3 Easy Ways To Change Admin URL in Magento 2

Are you still using the default admin URL for Magento 2? Have you wondered why there’s a weird string appended to your store’s admin URL? In this blog, I’m going to tell you why that string exits and how to prevent it from your store.

Why should we change admin URL?

When you install Magento 2, it will automatically create an admin URL with a random string. The admin URL allows you to access the backend of the store and then you can edit as well as manage the administrative tasks. However, the default format of the URL, “sitename.com/admin” is vulnerable by hackers. It is easy to crack the predictable names such as a backend, admin, etc. In order to prevent it, we should replace the default URL with a complex one. Here’re 3 methods we give you to help you change the admin URL with ease. Let’s enjoy it with a few clicks!

3 ways to change the Admin URL

Method #1: Use admin panel configuration.

This the simplest and easiest method to change the admin URL. 

In your Magento 2 admin panel, access Stores > Settings > Configuration

  1. On the left menu, under Advanced section, click on Admin
  2. Expand the Admin Base URL section
  3. Set Use Custom Admin URL to “Yes”. Then, enter the Custom Admin URL in the following format: http://yourdomain.com/magento/
  4. Set Custom Admin Path to “Yes”. Then, enter the Custom Admin Path. The path that you enter is appended to the Custom Admin URL after the last forward slash.
  5. Click the Save Config button.


Change admin URL by using admin panel configuration


Method #2: Change the admin path in Config.php

  1. Log into your server via ssh using an SSH or FTP client . Navigate to the app/etc folder and open env.php file in a text editor.
  2. Look for the code that says ‘frontName’ and replace the code in the quotes to the right of ‘frontName’ and replace ‘admin’ your new admin URL.
  3. Flush Cache.

return array (

        ‘backend’  =>

        array (

             ‘frontName’ => ‘admin’, 


Method #3: Change from the Server Command Line

  1. Log in your Magento hosting server via SSH. Navigate to the root directory of your store.
  2. Run this command: php bin/magento setup:config:set –backend-frontname=“newadminurl”
  3. Within the quotes for backend frontname – type in your desired new URL.
  4. If you would like to check or view your admin URL via command line: magento info:adminurl


Here is a quick guide on how to change admin URL in Magento 2. This needs to be done for security reasons to prevent hacking/cracking issue. After referring these methods, you can type the new admin URL and log in as usual.