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 http://www.example.com/onestepcheckout/

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 

5 comments:

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...

Hi,

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;

Gives: http://www.peta.cl/media/paymentlogo/default/mp10_1.gif


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]: http://www.peta.cl/media/index/index/secure/1/paymentlogo/default/mp10_1.gif

return Mage::getUrl('media' . 'paymentlogo/' . $logo, array('_secure'=>true));
Gives [Wrong]: https://www.peta.cl/mediapaymentlogo/default/mp10_1.gif/

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

Any idea ??

Appreciate your help from Chile !

Regards,

Nicolas

Janzell Jurilla said...

Hi Nicolas,

Try using:

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


Let me know if it works?

- Janzell

Anonymous said...

Hi

Thanks for sharing..