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.

4.9
(based on 11 Reviews)
How to Get Magento 2 Base URLAuthor Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply

Your email address will not be published.