Get Magento 2 base URL
Using Object Manager
Base Url:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get(‘\Magento\Store\Model\StoreManagerInterface’);
$storeManager->getStore()->getBaseUrl();
Base Url without index.php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get(‘\Magento\Store\Model\StoreManagerInterface’);
$storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
For getting media base url:
$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
for getting link url:
$this->_storeManager->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);