在非安全magento页面上将https重定向到http

Joh*_*ing 6 magento

Magento有一些很棒的内置功能,如果你请求一个安全的页面,例如通过http结账,那么它会重定向到https.然而,似乎缺乏的是,如果某人请求一个不需要安全的页面,例如通过https的类别页面,那么似乎没有将它们重定向到http的功能.

所以,如果有人要求:

https://www.mysite.com/mycategory

他们将301重定向到

http://www.mysite.com/mycategory

有人设法实现这一目标吗?

如果没有,那么任何人都可以指向我的重定向到HTTPS的magento核心代码的位置,然后我应该能够从中做出努力来提出解决方案.

小智 7

看看下面的方法

app/code/core/Mage/Core/Controller/Varien/Router/Standard.php::_checkShouldBeSecure()
Run Code Online (Sandbox Code Playgroud)


Joh*_*ing 6

所以感谢Rich我在app/code/core/Mage/Controller/Varien/Router/Standard.php :: _ checkShouldBeSecure()中跟踪了这个

我修改了这个函数(在app/code/local中创建的副本添加修改它)添加在elseif部分

protected function _checkShouldBeSecure($request, $path='')
{
    if (!Mage::isInstalled() || $request->getPost()) {
        return;
    }

    if ($this->_shouldBeSecure($path) && !Mage::app()->getStore()->isCurrentlySecure()) {
        $url = $this->_getCurrentSecureUrl($request);

        Mage::app()->getFrontController()->getResponse()
            ->setRedirect($url)
            ->sendResponse();
        exit;
    } elseif (!$this->_shouldBeSecure($path) && Mage::app()->getStore()->isCurrentlySecure()) {
        $url = $this->_getCurrentUnsecureUrl($request);

        Mage::app()->getFrontController()->getResponse()
            ->setRedirect($url)
            ->sendResponse();
        exit;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后添加了这个功能

protected function _getCurrentUnsecureUrl($request)
{
    if ($alias = $request->getAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS)) {
        return Mage::getBaseUrl('link', false).ltrim($alias, '/');
    }

    return Mage::getBaseUrl('link', false).ltrim($request->getPathInfo(), '/');
}
Run Code Online (Sandbox Code Playgroud)