7

How to get Configuration->Web->Base URLs -> Base URL in multi store magento 2. I have enabled Add Store Code to Urls

I have use on phtml page but it return me url with store code and I need only base url without store code:

<?php echo $block->getBaseUrl();?>

Output of above code is www.example.com/de and my requirement is www.example.com

This is magento1 code.

Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_UNSECURE_URL);

I need it in magento 2.

2

2 Answers 2

7

I have found solution. Bellow is my code.

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue("web/unsecure/base_url");?>

Thanks.

1
  • 2
    This works, but please don't use the ObjectManager. Inject the class Magento\Framework\App\Config\ScopeConfigInterface into the constructor, assign it to a class variable and use it from there. Oct 6, 2017 at 7:19
1

Use below code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);
3
  • i have check your solution but it still give result www.example.com/de. Dec 13, 2016 at 9:19
  • thanks for help. now i found solution.I have added my solution in answer Dec 13, 2016 at 9:29
  • 2
    In my case I used this one $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB)
    – embed0
    May 6, 2019 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.