Get Base Url in Model or Plugin file Magento 2.

You can get the base URL of the store in the controller file using Store Manager Interface.

To Retrieve the Base URL of the current store, You need to instantiate constructor in your controller file,

Check below code snippet for getting base URL,

echo $this->getStoreUrl();
Output:
http://magento2.docker/en (With Current store code in multiple store site)

  • If you want to only URL without store code,

Output:
http://magento2.docker (without store code at suffix)