How to Get Base URL in Magento 2

In this tutorial, you will go through how to get base url in Magento 2. There are several ways to get the base url of your Magento 2 website.

If you want to get Base URL , then you can try below code:

Get Base Url(Method 1):


Get Base Url(Method 2):

You can also use the following code which gives you the base url as well.


Get Media Base URL:


Get Link Base URL:


Get Base URL With Template File(.phtml):

Also,you can get base url directly at phtml using direct call of object Manager.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');

That’s it!

Hope this is useful for you 🙂

(Visited 6 times, 1 visits today)
Chandra Kumar

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of

0 Comment

Leave a Comment

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