How to get secure url in Magento

Posted by Damodar Bashyal on September 05, 2014

 

magento get secure base url

How do you get secure or unsecure urls in magento? It's quite simple actually. We discussed about getting different base url types in previous blog post here - [Magento get base url].

Now we will show you how to get secure urls in magento. So in previous post we got base url as:

Mage::getBaseUrl();
Mage::getBaseUrl('skin');
// etc...

Also, in one of our previous magento post, we mentioned this:

Mage::getUrl('');

Now, we are going to add extra param, so magento returns secure url as we are after. We just need to add 'true' as second parameter when we need secure url.

Mage::getBaseUrl('type_of_link', 'secure_or_unsecure');

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

And for: Mage::getUrl($route, $params); you can pass array('_secure'=>true) as second parameter to get secure urls like this:

Mage::getUrl('',array('_secure'=>true));
Mage::getUrl('mymodule/mycontroller/action', array('_secure'=>true));

References:

Mage.php and app/code/core/Mage/Core/Model/Store.php

Top Magento Extension to Power Your Magento Store posted on - Tuesday 11th of November 2014 01:38:13 AM

Great post to get url in Magento and I got a solution of my problem that I was facing in Magento development.

Magento Development posted on - Wednesday 30th of August 2017 11:49:43 AM

Mage::getUrl or Mage::getBaseUrl are secure to utilize during magento development. Both are naturally identify page is secure or not when you don't indicate it.
 
not published on website


QR Code: How to get secure url in Magento