I have custom script located inside Magento root directory used for ajax call. I am wondering what would be the safest way to get proper root url, no matter which store is user currently at.

Will Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) always show root url without index.php or store code or anything else inside url?

I made some testing and it looked fine, but maybe I missed something that will show up on one of the 1000 different stores where this will be used. This is why I am asking this question.



This should get you what you need:

| improve this answer | |
  • This is not correct, I need root url, not store url. Mage::getUrl('') will return www.domain.com/storecode and not www.domain.com – JohnyFree Apr 27 '16 at 12:38
  • what do you mean by root url then? Root is relative to a store view. – Marius Apr 27 '16 at 13:14
  • Url of folder where index.php file is located. If I put custom.php script to Magento root, I need to find out url of this script. Mage::getUrl('') will return www.domain.com/storecode but index.php is inside www.domain.com and not inside www.domain.com/storecode/ – JohnyFree Apr 27 '16 at 14:39

Should do it and always give you the url without Index.php

| improve this answer | |
  • Tnx but index.php is not the only worry, also store code and other things. If my custom script custom.php is inside Magento root and if user has multidomain store using the same Magento instance. I need to make sure that in such case Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL)."/custom.php" will always call custom.php script. – JohnyFree Apr 27 '16 at 13:03
  • Did you try it out? – Klettseb Apr 27 '16 at 13:04
  • Yes I tried in my store and it works, I just want to make sure it will work also on other 1000+ stores with different store configurations :) – JohnyFree Apr 27 '16 at 14:40
  • It should in my opinion :-) – Klettseb Apr 27 '16 at 14:53

I think this function will help you: Mage::getBaseUrl();

| improve this answer | |

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.