How to Change Magento 2 Admin URL (3 Methods)

Changing the Magento 2 Admin URL is an important security measure for your store. By replacing the default admin path with a custom one, you reduce the chance of automated bots or attackers targeting your backend and gain an extra layer of protection for sensitive data.

What Is the Admin URL in Magento 2?

The Admin URL is the address you use to access your Magento backend. From this panel, you can manage orders, customers, products, configuration, and extensions.

During installation, Magento 2 generates a random admin path. A common example looks like:

https://yourdomain.com/magento/admin_1a2b3c

Because predictable URLs are easier to attack, changing the default admin path is considered a best practice.

Why Change the Magento 2 Admin URL?

  • Default admin URLs are easier for hackers and bots to guess.
  • Custom URLs help protect against brute-force attacks.
  • Improves the overall security posture of your store.
  • Follows Magento security best practices for production environments.

Things to Know Before Changing the Admin URL

  • Have a developer on standby: If something goes wrong and you cannot access the admin panel, you may need server-level access to fix it.
  • Use a development/staging environment first: Test your changes before applying them to production to avoid downtime.
  • Check with your hosting provider: Ensure that they allow URL/path changes and that no extra restrictions are in place.
  • Be careful editing server files: If you are not familiar with modifying configuration files, involve someone who is.
Tip: Always back up your env.php and configuration before changing the admin URL.

3 Ways to Change Magento 2 Admin URL

Method 1 – Change Admin URL from the Admin Panel

  1. Log in to your Magento 2 Admin panel.
  2. Go to Stores > Settings > Configuration.
  3. Under the left menu, expand ADVANCED and click Admin.
  4. Expand the Admin Base URL section.
  5. Set Use Custom Admin URL to Yes.
  6. In Custom Admin URL, enter your full custom URL, ending with a slash (for example https://yourdomain.com/my-secret-admin/).
  7. Set Use Custom Admin Path to Yes.
  8. In Custom Admin Path, enter the new path only (for example my-secret-admin).
  9. Click Save Config.
  10. Log out and then log in again using the new Admin URL.

Method 2 – Change Admin URL via Command Line

Use this method if you have SSH access to the server and prefer CLI operations.

  1. Log in to your Magento hosting server using SSH.
  2. Navigate to your Magento 2 root directory.
cd /path/to/magento/root
  1. Run the following command to set a new backend front name:
php bin/magento setup:config:set --backend-frontname="custom_admin_path"

Replace custom_admin_path with your desired admin path (for example my-secret-admin).

After that, clear cache if needed and access your admin panel via the new URL:

https://yourdomain.com/custom_admin_path

Method 3 – Change Admin URL by Editing env.php

This method is useful when you cannot access the admin panel but still have file system access.

  1. Open the file app/etc/env.php in a text editor.
  2. Locate the backend configuration node:
'backend' => [
    'frontName' => 'admin'
],
  1. Change the frontName value to your custom path, for example:
'backend' => [
    'frontName' => 'custom_admin_url'
],
  1. Save the file.
  2. Clear the Magento cache:
php bin/magento cache:flush

Now you can access the admin panel at:

https://yourdomain.com/custom_admin_url

Conclusion

Changing the Magento 2 Admin URL is a simple but powerful way to harden your store’s security. Whether you use the Admin panel, command line, or directly edit env.php, the key is to choose a unique, non-obvious URL and document it securely for your team.

Combined with other security best practices (strong passwords, 2FA, IP whitelisting, and regular updates), a custom admin URL helps protect sensitive data, maintain customer trust, and ensure smooth operation of your e-commerce business.