skip to Main Content

I’m using below code to get base url in magento 2.

$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
echo $baseurl = $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB); 

Let me know how to get secure base url.

2

Answers


  1. Your code is correct, just pass the second parameter boolean true with getBaseUrl() method, by default its null, use below code like :

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    echo $baseurl = $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB); 
    echo $secureBaseUrl = $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB,true); 
    
    Login or Signup to reply.
  2. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    echo $secureBaseUrl = $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_WEB,true);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search