我想将我的自定义 html block 重定向到特定的 url。
我正在尝试:
class Mage_Page_Block_Html_World extends Mage_Core_Block_Template {
function __construct()
{
$i = 0;
parent::__construct();
$this->setTemplate('page/html/world.phtml');
$this->setCookie();
}
public function setCookie()
{
$lang = $this->getLanguageCode();
if(isset($_GET['country'])) {
$country = $_GET['country'];
Mage::getModel('core/cookie')->set('country', $country);
} else {
$country = Mage::getModel('core/cookie')->get('country');
}
/*Redirect to cookie url*/
if($country) {
try {
$url = "http://myurl.dev/".$country."/";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), "\n";
}
}
}
因为我在 .htaccess 中使用了多商店配置,所以我使用:
SetEnvIf 主机 www.myurl.dev MAGE_RUN_CODE=base
SetEnvIf 主机 www.myurl.dev MAGE_RUN_TYPE=网站
SetEnvIf 主机 ^myurl.dev MAGE_RUN_CODE=base
SetEnvIf 主机 ^myurl.dev MAGE_RUN_TYPE=网站
SetEnvIf 主机 www.myurl1.dev MAGE_RUN_CODE=vs
SetEnvIf 主机 www.myurl1.dev MAGE_RUN_TYPE=网站
SetEnvIf 主机 ^myurl1.dev MAGE_RUN_CODE=vs
SetEnvIf 主机 ^myurl1.dev MAGE_RUN_TYPE=网站
问题: 通过此重定向,我收到错误 310:重定向过多。 我不知道如何解决这个问题。
最佳答案
考虑到框架架构,这是一种不合适的方法。作为开发人员,您可以使用多种机制来解析代码并触发重定向。当前的方法是使用 View 层来触发重定向,而请求 Controller 层和事件观察器系统会更合适。
controller_action_predispatch
事件适用于所有请求范围,并且每个路由都有目标预分派(dispatch)事件。您可以使用它们和 Mage_Core_Controller_Request_Http
对象(“请求对象”)来触发重定向。
关于html - Magento 从 HTML block 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11501091/