2

I've configured magento to use SSL links..

Base URL      https://sub.domain.com/
Base Link URL {{secure_base_url}}
Base ... URL  {{secure_base_url}}.../

Use Secure URLs in Frontend: YES
Use Secure URLs in Backend:  YES

Frontend i have some custom links built with Mage::getUrl([...])

<?php
// link to CMS page
echo Mage::getUrl('help'); //-> http://sub.domain.com/help/
// link to customer account
echo Mage::getUrl('customer/account'); //-> httpS://sub.domain.com/customer/account/
?>

Why is there a difference in protocol?

// Roland

Roland Franssen
  • 1,038
  • 1
  • 11
  • 22

4 Answers4

5

I had an issue with https in my custom module; my work around was like this:

$loadFromSSL = $_SERVER['SERVER_PORT']==443?true:false;

Mage::getUrl('', array('_secure'=>$loadFromSSL))
Michael Fredrickson
  • 36,839
  • 5
  • 92
  • 109
  • This worked, but I always thought that Mage::getUrl() would render http/https correctly, but I was having issues and this fix worked for me. – Mike D Nov 04 '11 at 17:25
4

In app/code/core/Mage/Customer/etc/config.xml there's an entry for frontend/secure_url for /customer.

This will help

Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28
Greg
  • 10,350
  • 1
  • 26
  • 35
  • What's the best practice to set this as default, in other words; if secured urls is configured to 'YES' i just want all my internal links to start with https:// – Roland Franssen Sep 14 '09 at 09:05
  • probably best to extend or over-ride the helper that does the URL building, and runs the check against config for whether it should be secure or not. Off the top of my head, it will be in app/code/core/Mage/Core/Helper/Url.php (maybe Model/Url.php?) and you'd want to copy it to the same place under code/local or, if you have a module of your own already, you could put a rewrite into the config.xml and just over-ride the bit you need. – Greg Sep 14 '09 at 18:00
4

I think this is better (from: http://thecompleteprogramer.wordpress.com/2012/09/11/magento-get-url-with-or-without-secure-path-according-to-current-url-protocol/)

Mage::getUrl('yourpath', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
pspahn
  • 2,770
  • 4
  • 40
  • 60
0

this worked to me

echo Mage::getUrl('customer/account/loginPost',array('_secure'=>true));

For example:

if you browsing with http then

echo Mage::getUrl('customer/account/loginPost',array('_secure'=>true));
// http://dominio.com/customer/account/loginPost

if you browsing with https then

echo Mage::getUrl('customer/account/loginPost',array('_secure'=>true));
// https://dominio.com/customer/account/loginPost