如果您请求应该安全的页面,Magento具有一些很棒的内置功能。通过http签出然后重定向到https。然而,似乎缺乏的是如果有人请求不需要安全的页面,例如通过https的类别页面然后似乎没有将它们重定向到http的功能。将https重定向到非安全magento页面上的http
所以,如果有人要求:
他们得到301重定向到
任何人都成功地实现这一目标?
如果没有,那么任何人都可以指向我的magento核心代码的位的方向,重定向到HTTPS,然后我应该能够从中提出解决方案。
如果您请求应该安全的页面,Magento具有一些很棒的内置功能。通过http签出然后重定向到https。然而,似乎缺乏的是如果有人请求不需要安全的页面,例如通过https的类别页面然后似乎没有将它们重定向到http的功能。将https重定向到非安全magento页面上的http
所以,如果有人要求:
他们得到301重定向到
任何人都成功地实现这一目标?
如果没有,那么任何人都可以指向我的magento核心代码的位的方向,重定向到HTTPS,然后我应该能够从中提出解决方案。
在下面的方法看看
app/code/core/Mage/Core/Controller/Varien/Router/Standard.php::_checkShouldBeSecure()
所以感谢丰富的I在app /代码/核心/法师/控制器/瓦瑞恩/路由器/ Standard.php :: _ checkShouldBeSecure跟踪下来()
予修正(/本地附加修正它有创建的副本在应用程序/代码)将在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;
}
}
然后加入这此函数功能
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(), '/');
}
非常感谢以上提示。我将代码集成到“Magento-like-module”中,不会超载Core。
只有三个文件,以创建:
app/code/local/MyCompany/MyModule/Controller/Varien/Router/Standard.php
app/code/local/MyCompany/MyModule/etc/config.xml
app/etc/modules/MyCompany_MyModule.xml
在app/etc/modules/MyCompany_MyModule.xml
粘贴以下无趣的东西:
<?xml version="1.0"?>
<config>
<modules>
<MyCompany_MyModule>
<active>true</active>
<codePool>local</codePool>
</MyCompany_MyModule>
</modules>
</config>
在app/code/local/MyCompany/MyModule/etc/config.xml
粘贴路由器配置:
<?xml version="1.0"?>
<config>
<modules>
<MyCompany_MyModule>
<version>0.1.0</version>
</MyCompany_MyModule>
</modules>
<default>
<web>
<routers>
<standard>
<area>frontend</area>
<class>MyCompany_MyModule_Controller_Varien_Router_Standard</class>
</standard>
</routers>
</web>
</default>
</config>
而且在app/code/local/MyCompany/MyModule/Controller/Varien/Router/Standard.php
执行逻辑从以上:
<?php
class MyCompany_MyModule_Controller_Varien_Router_Standard extends Mage_Core_Controller_Varien_Router_Standard {
protected function _checkShouldBeSecure($request, $path='') {
parent::_checkShouldBeSecure($request, $path);
if (!$this->_shouldBeSecure($path) && Mage::app()->getStore()->isCurrentlySecure()) {
$url = $this->_getCurrentUnsecureUrl($request);
Mage::app()->getFrontController()->getResponse()
->setRedirect($url)
->sendResponse();
exit;
}
}
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(), '/');
}
}
不幸的是,没有事件,观察它解决了这一问题。但覆盖路由器比(技术上)更换更好(更新)。
有关更多知识,请办理以下
检查如何解决自定义模块前端的URL的问题是被迫HTTPS。而不是http。如果您使用过模块创建器来创建模块。比你会在config中定义下面的代码。XML
<admin>
<routers>
<[ModuleName]>
<use>admin</use>
<args>
<module>[NameSpace_ModuleName]</module>
<frontName>[frontName]</frontName>
</args>
</[ModuleName]>
</routers>
</admin>
要解决重定向问题为https而非http,你需要从以上模块config.xml文件路径代码评论:应用程序/代码/(codepool)/(命名空间)/(模块名)/等/config.xml或者你可以为路由器添加不同的“frontName”。例如:
<admin>
<routers>
<[ModuleName]>
<use>admin</use>
<args>
<module>[NameSpace_ModuleName]</module>
<frontName>[frontName]</frontName>
</args>
</[ModuleName]>
</routers>
</admin>
<frontend>
<routers>
<[ModuleName]>
<use>standard</use>
<args>
<module>[NameSpace_ModuleName]</module>
<frontName>[frontName1]</frontName>
</args>
</[ModuleName]>
</routers>
</frontend>
按照上面的代码管理URL将http://yourdomain.com/index.php/frontName/adminhtml_moduleName/和前端网址会像:http://yourdomain.com/index.php/frontName1
我希望以上内容对你有用。
上面的代码剥离了请求中的查询字符串,这两个函数都应该在重定向之前将其添加到请求中。
见下文:
$querystring = $_SERVER['QUERY_STRING'];
return Mage::getBaseUrl('link', false).ltrim($request->getPathInfo(), '/').($querystring ? '?'.$querystring : '');
干杯丰富的只是发现。 –