Reading list Switch to dark mode

    Get Admin path in Magento 2 programmatically

    Updated 26 June 2022

    Hello Guys!!!

    In this article, we are going to learn how we can get an admin path/URI programmatically.

    Here, we can get the admin URI by using the following ways:

    1. By using AreaList: In this method, we will create an instance of \Magento\Framework\App\AreaList class and call the getFrontName method as follows:

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $areaList = $objectManager->get("\Magento\Framework\App\AreaList");
    $adminPath = $areaList->getFrontName('adminhtml');

    2. By using Backend Helper: In this method, we will create an instance of \Magento\Backend\Helper\Data class and call the getAdminFrontName method as follows:

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $backendHelper = $objectManager->get("\Magento\Backend\Helper\Data");
    $adminPath = $backendHelper->getAdminFrontName();

    Note: The above-mentioned 1st method may not work in some cases, then you can go for the 2nd method. For example, if you have set wild card DNS entry settings for your instance and want to display a Magento admin login page link at frontend pages and frontend stores URLs may be like: https://maindomain.com or https://xyz.maindomain.com then, in this case, in the first case, for URL https://xyz.maindomain.com, you will not get any value for admin path URL, then you can use 2nd method(using Backend helper).

    3. By using CLI: You can execute the following command in CLI to get the admin path URI:

    php bin/magento info:adminuri

    After executing the above command, the result will be as follows:

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    Admin URI: /admin_webkul

    Hope this will be helpful.
    Thanks 🙂

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home