Zend 框架重定向列表 url
Zend framework redirect list urls
我想在我的 Zend Framework 1 应用程序中重定向 url 的列表。现在我可以像这样将所有数百个重定向添加到 htaccess 文件中:
Redirect 301 /old-page.html /new-page.html
但我更愿意创建一个包含所有重定向的有组织的文件。这可能吗?我阅读了一些有关 .ini 文件的内容,但我想这并不是我真正想要的。
类似以旧 url 作为键和新 url 作为值的数组也不错。但是我对 Zend Framework 很陌生,所以也许有人可以帮助我吗?我想我需要创建一个 PHP 文件并将其加载到 bootstrap 中,但我正在努力解决这个问题。
编辑:
就在我的脑海里,我想像这样的东西会很好:
rewrites.php
$rewrites = array(
'/old_url.html' => '/new_url.html'
);
if(array_key_exists(Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(), $rewrites)){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$rewrites[Zend_Controller_Front::getInstance()->getRequest()->getRequestUri()]);
}
您可能想要做的是注册一个插件。然后,该插件将检查传入的请求,如果满足某些条件,则重定向请求。
Library/App/Controller/Plugin/RedirectHandler.php
<?php
class App_Controller_Plugin_RedirectHandler
extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup
(Zend_Controller_Request_Abstract $request)
{
// best to load this from somewhere, but we'll
// put it here for illustration purposes
$bindings = array(
'/old_url.html' => '/new_url.html'
);
$uri = $request->getRequestUri();
if (isset($bindings[$uri])) {
$this->getResponse()
->setRedirect($bindings[$uri], 301)
->sendResponse();
exit;
}
}
}
然后我们需要确保调用处理程序。
Application/Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
// ...
protected function _initControllerPlugins ()
{
Zend_Controller_Front::getInstance()
->registerPlugin(new App_Controller_Plugin_RedirectHandler());
}
}
我想在我的 Zend Framework 1 应用程序中重定向 url 的列表。现在我可以像这样将所有数百个重定向添加到 htaccess 文件中:
Redirect 301 /old-page.html /new-page.html
但我更愿意创建一个包含所有重定向的有组织的文件。这可能吗?我阅读了一些有关 .ini 文件的内容,但我想这并不是我真正想要的。
类似以旧 url 作为键和新 url 作为值的数组也不错。但是我对 Zend Framework 很陌生,所以也许有人可以帮助我吗?我想我需要创建一个 PHP 文件并将其加载到 bootstrap 中,但我正在努力解决这个问题。
编辑:
就在我的脑海里,我想像这样的东西会很好:
rewrites.php
$rewrites = array(
'/old_url.html' => '/new_url.html'
);
if(array_key_exists(Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(), $rewrites)){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$rewrites[Zend_Controller_Front::getInstance()->getRequest()->getRequestUri()]);
}
您可能想要做的是注册一个插件。然后,该插件将检查传入的请求,如果满足某些条件,则重定向请求。
Library/App/Controller/Plugin/RedirectHandler.php
<?php
class App_Controller_Plugin_RedirectHandler
extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup
(Zend_Controller_Request_Abstract $request)
{
// best to load this from somewhere, but we'll
// put it here for illustration purposes
$bindings = array(
'/old_url.html' => '/new_url.html'
);
$uri = $request->getRequestUri();
if (isset($bindings[$uri])) {
$this->getResponse()
->setRedirect($bindings[$uri], 301)
->sendResponse();
exit;
}
}
}
然后我们需要确保调用处理程序。
Application/Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
// ...
protected function _initControllerPlugins ()
{
Zend_Controller_Front::getInstance()
->registerPlugin(new App_Controller_Plugin_RedirectHandler());
}
}