For example:
http://yourhost/entry/123/
redirect to (301)
http://yourhost/entry/123
First. write your frontController plugin in application/plugins/MyUrlPlugin.php
class MyUrlPlugin extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$path = $request->getPathInfo();
$uri = $request->getRequestUri();
if($path != '/' && strrpos($path,'/') == strlen($path)-1){
// 301 redirect
$this->getResponse()
->setRedirect(rtrim($path,'/') . preg_replace('#^.*\?#','?',$uri) ,301)
->sendResponse();
exit();
}
}
}
and, register your plugin to frontController.
in public/index.php:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();
$front = Zend_Controller_Front::getInstance();
// register your plugin
require_once 'plugins/MyUrlPlugin.php';
$front->registerPlugin(new MyUrlPlugin);
//start your application
$application->run();
That's all.
Date: 2012-01-17 22:01:56 and last modified: 2012-01-17 22:43:37
Recent entries:
- Emacs rainbow mode
- Squirm a url rewriter for squid
- How to use rsync for transferring files over ssh
- Vide: GRE tunnel
- Video: how to install freebsd
- Video: Install zend framework
- Video: Install Window7 from network
- Install Window7 from a PXE Boot server (Linux/FreeBSD)
- Create GRE tunnel with FreeBSD8
- What's cooking for FreeBSD 9