How to Get Magento 2 Base URL

How to Get Magento 2 Base URL

As a Magento 2 developer, I many times require to get Magento 2 base URL.

In good old days of Magento 1, it was easier to get the base URL using Mage::getBaseUrl();

However, it is not the same case in Magento 2.

You can use the two methods to get base URL in Magento 2:

  1. Using Magento Core Method
  2. Using Object Manager

I have shown the implementation of both the methods below:

Methods to Get Magento 2 Base URL:

  1. Using Magento Core Method

  2. Using Object Manager

That’s it

Feel free to share the post and use the Comments section below if you have any doubts on the topic. I’d be happy to solve it asap.

Thanks.

5
(based on 5 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply