How To Use A Custom Admin URL in Magento 2

As a security best practice, the default “admin” link or “backend” link is not recommended for your Magento 2 platform web store. Instead of that, you should use custom Admin URL. It will not completely protect your web store from a bad actor, but at least it will avoid to be gain unauthorized access from bad script.

Before executing a custom Admin URL, check with your hosting provider . Some hosting providers require a standard URL to meet firewall protection rules.

In a general Magento installation, the Admin URL and path is under the Magento base URL. The Admin path is one directory under the root.

Default Base URL

http://yourdomain.com/magento/

Default Admin URL and Path

http://yourdomain.com/magento/admin

You can edit the Admin URL and path to another location, however if you have any mistake in editing progress, the access to admin will be removed, and must be fixed from the server. So do not do it by yourself unless you know how to edit configuration files on the server.

Method 1: Change from the Magento Admin

  1. On the Admin sidebar, click Stores. Under Settings, click Configuration. On the left of the panel under Advanced, click Admin
  2. Open the Admin Base URL tap and follow these steps:
  • Uncheck all Use system value checkboxes
  • Set Use Custom Admin URL to “Yes”
  • Input the Custom Admin URL in the following example: http://yourdomain.com/magento/

The Admin URL must be in the same Magento installation, and have the same document root as the storefront.

  • Set Custom Admin Path to “Yes”
  • Input the Custom Admin Path. The path that you enter is appended to the Custom Admin URL after the last forward slash: sample_custom_admin
Admin Base URL Custom Admin URL In Magento 2
Admin Base URL
  1. Click Save after completing
  2. Sign out then log back using the new Admin URL and path.

Method 2: Change from the Server Command Line

Use notepad or any text editor to open app/etc/env., edit the name of the [admin] path using lowercase only. Save the file.

Clear cache by System > Tools > Cache Management > Flush Magento Cache. Or delete the content of cache folder in var/cache folder.