Magento 2 – Get Base URL and Current URL

In this post, we will show you how to get base url and current url in Magento 2. 

If you want to get Base url:

Where $storeManager is instance of \Magento\Store\Model\StoreManagerInterface

You also can use ObjectManager if $storeManager is not available

For Getting Media Url Use Below code:

Get Static content Url

Get Current URL

However, using object manager is not a recommend way. You should init $storeMaanger variable in __construct() method

Then use following code to get URLs

This is the guide to get base URL and other URLs in Magento 2. If that you have any queries about the article or any questions in general, use the comment section below or contact us

Rate this post

Written By Metagento

Leave a Reply

Your email address will not be published.