【发布时间】:2013-01-11 19:32:37
【问题描述】:
我使用 mod_rewrite 的 RewriteRules 在 apache 上有几个基本重定向。 我想使用 Zend Framework 以编程方式进行这些重定向。 这些重定向可能包括不同的域。 例如
RewriteRule ^/xmas(.*) http://mycdn.com/things/xmas$1 [P]
使用 Apache 重定向时,url 保持不变,例如在浏览器的地址栏上。我想在 ZF 中模仿这种行为,但找不到其他域的方法。
我可以通过扩展Zend_Controller_Router_Route、扩展match() 方法,然后返回一个包含模块、控制器、操作等字段的数组来实现站点内重定向。
class My_Route extends Zend_Controller_Router_Route
{
// ...
public function match($path)
{
// ...
return
array(
'module' => 'default',
'controller' => 'mycontroller',
'action' => 'index',
);
}
}
但我还没有设法使它适用于重定向到其他域,因为它显然只适用于站点内路由(也没有找到在规范中指定域或完整 url 的方法)。
我尝试了其他方法,例如:
$r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$r->gotoUrl("http://otherdomain.com/some-stuff-to-redirect-to")->redirect();
这会进行重定向,但它会完全改变页面,发出一个全新的请求。
我如何在 ZF 中实现这一点? 使用 ZF1。
【问题讨论】:
标签: zend-framework redirect url-rewriting zend-route