【问题标题】:Magento SSL linksMagento SSL 链接
【发布时间】:2010-11-27 13:06:56
【问题描述】:

我已将 magento 配置为使用 SSL 链接..

基本 URL https://sub.domain.com/ 基本链接 URL {{secure_base_url}} 基础... URL {{secure_base_url}}.../ 在前端使用安全 URL:是 在后端使用安全 URL:是

前端我有一些使用 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/
?>

为什么协议不同?

// 罗兰

【问题讨论】:

    标签: php ssl magento geturl


    【解决方案1】:

    app/code/core/Mage/Customer/etc/config.xml 中有一个frontend/secure_url 对应/customer 的条目。

    这会有所帮助

    【讨论】:

    • 换句话说,将其设置为默认值的最佳做法是什么;如果安全网址配置为“是”,我只希望我的所有内部链接都以 https:// 开头
    • 可能最好扩展或覆盖执行 URL 构建的帮助程序,并针对配置运行检查它是否应该是安全的。在我的脑海中,它将位于 app/code/core/Mage/Core/Helper/Url.php (可能是 Model/Url.php?)中,您希望将其复制到 code/ 下的同一位置本地的,或者,如果您已经有自己的模块,您可以在 config.xml 中进行重写,然后覆盖您需要的部分。
    【解决方案2】:

    我在自定义模块中遇到了 https 问题;我的工作是这样的:

    $loadFromSSL = $_SERVER['SERVER_PORT']==443?true:false;
    
    Mage::getUrl('', array('_secure'=>$loadFromSSL))
    

    【讨论】:

    • 这行得通,但我一直认为 Mage::getUrl() 会正确呈现 http/https,但我遇到了问题,这个修复对我有用。
    【解决方案3】:

    我觉得这样更好 (来自: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()));
    

    【讨论】:

      【解决方案4】:

      这对我有用

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

      例如:

      如果您使用 http 浏览,那么

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

      如果您使用 https 浏览,那么

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-23
        相关资源
        最近更新 更多