Search This Blog

May 16, 2011

Https / Secure URL for Magento Links

Creating an secure link in Magento is pretty easy. You can use getUrl() function instead of using hardcoded https link. To do so, you need to insert one paramater in your getUrl() function to make your link an secure one. See Examples below.

Creating a link to onestepcheckout page

To get the URL in Magento Controller in http

<a href="<?php echo Mage::getUrl('onestepcheckout/’) ?>"></a>Checkout

This will produce a url like

Now you want to redirect to the secure version. Easy.
For mage core

<a href="<?php echo Mage::getUrl('onestepcheckout/, array('_secure'=>true)) ?>"></a>Checkout 

For phtml File you can do this:

<a href="<?php echo $this->getUrl('onestepcheckout/, array('_secure'=>true)) ?>"></a>Checkout 

For Static Block

<a href="{{base url=’ 'onestepcheckout/’,array(‘_secure’ =>true)}}</a>Checkout 


Paul Clegg said...

You can check to make sure that the URL should be secure by using the Mage::getSecure() function, which returns a boolean value. load it via Mage::getModel('core/url')->getSecure();

Janzell Jurilla said...

Hey Paul,

Thanks for sharing, that was also great tips.

Nicolas Mella said...


I hope you can help me.

I have the following code whch end in HTTP, but I need it in HTTPS:

return Mage::getUrl('media') . 'paymentlogo/' . $logo;


I try using many options from your example to get the HTTPS, but none of them worked for me:

return Mage::getUrl('media', array('secure'=>true)) . 'paymentlogo/' . $logo;
Gives [Wrong]:

return Mage::getUrl('media' . 'paymentlogo/' . $logo, array('_secure'=>true));
Gives [Wrong]:

return Mage::getUrl('media' . '/' . 'paymentlogo/' . $logo, array('_secure'=>true));
Gives [Error]:

Any idea ??

Appreciate your help from Chile !



Janzell Jurilla said...

Hi Nicolas,

Try using:

Mage::getUrl('', array('secure'=>true)) . 'media/paymentlogo/' . $logo;

Let me know if it works?

- Janzell

Anonymous said...


Thanks for sharing..