Kohana 3.2.6: Change Default Route

Let’s define a redirect module that will handle all requests that were not handled by any other controller. It will also be a good place to include a 404 page.

modules/application/bootstrap.php

Kohana::modules(array(
.
.
'redirect' => MODPATH . 'redirect', //Redirect module
.
.
));

Route::set('default', '(<request>)',
 array(
 'request' => '(.*)',
 ))
 ->defaults(array(
 'controller' => 'redirect',
 'action' => 'index',
 ));

 

And then define the controller itself:

modules/redirect/classes/controller/redirect.php

<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Handles all the redirecions that may happen
 *
 * @package......Redirect
 * @category.....SEO
 * @author.......Mauricio Otta
 * @copyright....PortNumber53.com
 */

class Controller_Redirect extends Controller {

  static public function action_index() {
    echo "Controller_Redirect::action_index();<br />";
    echo Request::current()->param('request');
  }

}

 

 

 

Bookmark the permalink.

Leave a Reply