10

I want to to get base-secure-url without index.php.

I enabled index.php for some reason. Now I have a PHP file at Magento root directory, and I want to call Magento secure pages from this PHP file.

Note: i have multi stores in my site

Please provide more ideas on this.

3

5 Answers 5

15
Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL);

I mention this because no one else has, but I prefer using Mage::getUrl or Mage::getBaseUrl. Both of those automatically detect if the page is already secure when you do not specify it.

3
  • is it working on multi store with different domain name
    – Amit Bera
    Commented Sep 13, 2014 at 11:23
  • You can specify a store with the second parameter of getStoreConfig. It accepts an ID, a code (as set in admin) or a Mage_Core_Model_Store object, just use whatever you have available in your code. Commented Sep 13, 2014 at 11:38
  • 2
    Replacing 'Mage::getUrl' with 'Mage::getBaseUrl' did the trick for me
    – Ronny
    Commented Jun 22, 2015 at 17:52
11

as @Aphroz said, you can use

Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true );

in order to retrieve secure base url. This returns secure url because we have specified it through second parameter true. Here first parameter is specified as Mage_Core_Model_Store::URL_TYPE_WEB. This means the method returns value correspond to this system configuration field web/secure/base_url. This field is the value that we specify at

 System  >  Configuration  > Web  >  Secure url

so if this field is not using index.php there along with the base url, then the method will not give index.php along with the url. If it holds index.php, then it will return the same. So to ensure index.php is not there you can use str_replace function.

1
  • Am I the only one who thinks this is a bug in Magento? The system should know when I am on a secure URL and then default all its Mage::getBaseUrl() to secure.
    – ESP32
    Commented Feb 23, 2016 at 18:21
5

Below URL Access list

Get URLs in CMS pages or static blocks

  1. Base URL:

    {{base url=''}}
    
  2. Store URL:

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

    also only store URL

    {{store url=""}}
    
  3. Media URL:

    only get media URL

    {{media url=''}}
    

    if you get some folder path

    {{media url='imagefolder/imagename.jpg'}}
    
  4. Skin URL:

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

    only get skin URL

    {skin url=''}}
    


Get URLs in PHP files (incl. templates/PHTML)

  1. Get Base Url in magento:

    $baseurl = Mage::getBaseUrl();
    

    Get Base Url without index.php

    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); 
    
    // output: http://example.com/
    
  2. Current Url

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

    or

    $currentUrl = Mage::getUrl('*/*/*', array('_current' => true));
    

    or

    if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute'))) 
    {
        $currentUrl = Mage::helper('core/url')->getCurrentUrl();
    }
    
  3. Skin URL:

    $skinUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
    

    Unsecure Skin URL:

    $skinUrl = $this->getSkinUrl('images/imagename.jpg');
    

    Secure Skin URL:

    $this->getSkinUrl('images/imagename.gif', array('_secure'=>true));
    
  4. Media URL

    $mediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
    

    or

    $mediaUrl = Mage::getBaseUrl('media');
    
  5. Get Js URL:

    $jsUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
    

    or

    $jsUrl = Mage::getBaseUrl('js');
    
  6. get store URL:

    $storeUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
    
  7. Get Home URL:

    $homeUrl= Mage::helper('core/url')->getHomeUrl();
    
  8. Get Directory paths

    Mage::getBaseDir('design') // Get design directory path
    Mage::getBaseDir('code')   // Gives code directory file path
    Mage::getBaseDir('lib')    // Gives lib directory file path
    Mage::getBaseDir('skin')   // Gives skin directory file path
    Mage::getBaseDir('var')    // Gives var directory file path
    Mage::getBaseDir('cache')  // Gives cache directory file path
    Mage::getBaseDir('log')    // Gives log directory file path
    
  9. Create module URL:

    Mage::getUrl('module/controller/action');
    

Get More details about get URLs

3

This should do the trick:

Mage::getBaseUrl('link',true);

Short and sweet.

1
  • That's the most solid approach, as it'll include any store_code to url, if that's the case Commented Oct 21, 2016 at 17:03
1

Can't you use this?

str_replace('index.php','whatever.php',Mage::getBaseUrl('web', true));
4
  • 2
    Dude,it is not proper way....
    – Amit Bera
    Commented Sep 13, 2014 at 7:34
  • 1
    Then Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ) as mentioned here: stackoverflow.com/questions/15002254/…
    – Aphroz
    Commented Sep 13, 2014 at 8:00
  • it not give result when i used secure url
    – Amit Bera
    Commented Sep 13, 2014 at 8:04
  • Not Sure, But .htaccess file can be helpful Commented Sep 13, 2014 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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