29

I have a form in Magento that is displayed over the insecure URL (http) but I need it to submit to the secure URL (https).

I display the URL I currently use the following code:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)

I am assuming I need to change the URL_TYPE_WEB to something else. Does anyone know what that something else is?

Josh Pennington
  • 6,418
  • 13
  • 60
  • 93

6 Answers6

49

Have you tried this?

Mage::getUrl('',array('_secure'=>true))

I think that gets you the base secure url, I believe.

Mage::getUrl('customer/account/login',array('_secure'=>true))

Will get you to the login page. In other words,

Mage::getUrl('module/controller/action',array('_secure'=>true))

Will get you to any page you want, just substitute 'module/controller/action' for the appropriate combo.

Edit -- Fixed Typos

Josh Pennington
  • 6,418
  • 13
  • 60
  • 93
shaune
  • 2,510
  • 1
  • 31
  • 36
  • 6
    As well as `_secure` there is also `_forced_secure`. A full reference can be found [here](http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters) – clockworkgeek Nov 24 '10 at 15:44
  • If you are loading a script rather than a site url, you'll get a trailing slash with this function, so be sure to `rtrim` out that slash. – jmargolisvt Aug 02 '16 at 19:55
11

http://blog.geekslikeshinythings.com/2014/12/magento-force-secure-urls-https-on-all.html

this works in Mageno 1.9.1 use your app/etc/config.xml file

<?xml version="1.0"?>
<config>
  <frontend>
    <secure_url>
      <all>/</all>
    </secure_url>
  </frontend>
</config>

If user is using https, this should force all urls to rewrite (created as) to https.

Artistan
  • 1,982
  • 22
  • 33
6

Use:

    Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL);

to read the the configuration value inside magento that has been set inside admin.

j0k
  • 22,600
  • 28
  • 79
  • 90
George Donev
  • 563
  • 7
  • 13
3

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
1

You can do this in code and also from xml.

For example, if you want to set https for the check out page then you have to add the below code in your custom config.xml:

<code>
        <secure_url>
                <checkout_onepage>/checkout/onepage</checkout_onepage>
                <checkout_multishipping>/checkout/multishipping</checkout_multishipping>
        </secure_url>
</code>

Magento has a default feature for https for check out so you can do the same thing for other pages like for the customer page:

<code>
        <secure_url>
                <customer>/customer/</customer>
        </secure_url>
</code>

I hope it'll help you.

cbascom
  • 766
  • 1
  • 5
  • 21
Asrar Malik
  • 125
  • 3
  • 8
0

Tried this its working for me.

Mage::getUrl('',array('_secure'=>true))

After added this code finally its look like below

IWD.ProductVideoView.urlGetVideo = "<?php echo Mage::getUrl('iwd_productvideo/player/getvideo/',array('_secure'=>true)); ?>?isAjax=true";
Randhir Yadav
  • 1,449
  • 15
  • 24