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
- On the left menu, under Advanced section, click on Admin
- Expand the Admin Base URL section
- Set Use Custom Admin URL to “Yes”. Then, enter the Custom Admin URL in the following format: http://yourdomain.com/magento/
- 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.
- Click the Save Config button.
Method #2: Change the admin path in Config.php
- 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.
- 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.
- Flush Cache.
<?php return array ( ‘backend’ => array ( ‘frontName’ => ‘admin’, ),
Method #3: Change from the Server Command Line
- Log in your Magento hosting server via SSH. Navigate to the root directory of your store.
- Run this command: php bin/magento setup:config:set –backend-frontname=“newadminurl”
- Within the quotes for backend frontname – type in your desired new URL.
- 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.