I have created multiple stores in one. Now when I change the store view it definitely changes and I have set the Base URLs for this store view accurately.
But when I try to get the current store view URL or Name I got the default store view name and URL.
I am trying to get using $storeManager->getStore()->getBaseUrl()
Any idea how I can get this ?

2 Answers 2


What you have to understand is the baseUrl is the same even you have multiple store views. the value that changes is for example : StoreId, StoreCode, storeName etc...

If you want to get the baseUrl, it will be the same in all stores :

$storeManager->getStore()->getBaseUrl() //domaine.com

if you want to get the currentUrl, it will be different in each store :

$storeManager->getStore()->getCurrentUrl() //domaine.com/?___store=default___from_store=pro
$storeManager->getStore()->getCurrentUrl($storeManager->getStore()->getId()) //domaine.com/?___store=default___from_store=2

If you want to set à specific store view, you append at the url ?___store=storeviewcode :

  • I guess magento gives the facility to each store view has its own Base URL. So there must be a way to get that, However if it is not possible then what is the alternate. I have tried your method but its still telling me that I am on default store view from_store=default
    – devZ
    Jan 17, 2020 at 10:50
  • Being precise I am in a Controller and receiving an Ajax and I want to know from which Store View it was generated.
    – devZ
    Jan 17, 2020 at 11:15

Magento Mage Core, Admin Static Blocks, or Phtml edits are usually includes getting url path such images, javascript, base url, media and store url. There are different ways to retrieve mentioned URL paths depending on where section you’re editing. To Retrieve URL path in STATIC BLOCK


{{skin url='images/sampleimage.jpg'}}

To get Media URL

{{media url='/sampleimage.jpg'}}

To get Store URL

{{store url='mypage.html'}}

To get Base URL

{{base url='yourstore/mypage.html'}}

TO Retrieve URL path in PHTML Note: In editing PHTML don't forget to enclode the following code with PHP tag

Not secure Skin URL:

<?php echo $this->getSkinUrl('images/sampleimage.jpg') ?>

Secure Skin URL

<?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>

Get Current URL

$current_url = Mage::helper('core/url')->getCurrentUrl();

Get Home URL

$home_url = Mage::helper('core/url')->getHomeUrl();

Get Magento Media Url


Get Magento Media Url


Get Magento Skin Url


Get Magento Store Url


Get Magento Js Url

  • Being precise I am in a Controller and receiving an Ajax and I want to know from which Store View it was generated.
    – devZ
    Jan 17, 2020 at 10:56
  • These are Magento 1 methods; the question was M2. Feb 19, 2020 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.