Mateusz
Mateusz

Reputation: 3048

Kohana 3.3 catch-all route

How can I define a route that will catch all requests and forward them to one specific controller? I've already tried adding the default route

Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
         'directory' => 'site',
         'controller' => 'foobar',
         'action' => 'foobar',
));

or

Route::set('default', '(.*)')
    -> defaults(array(
        'directory' => 'site',
        'controller' => 'foobar',
        'action' => 'foobar',
));

to my bootstrap.php, but it doesn't work. After typing localhost/a I get either

Unable to find a route to match the URI: a

or

The requested URL a was not found on this server.

error. I'm sure that the controller is valid, as

Route::set('foobar', 'foo') 
    -> defaults(array(
        'directory' => 'site',
        'controller' => 'foobar',
        'action' => 'foobar',
));

works fine.

I'm using Kohana 3.3.

Upvotes: 3

Views: 1140

Answers (1)

ITroubs
ITroubs

Reputation: 11215

This should work:

Route::set('foobar', '<catcher>',array('catcher'=>'.*')) 
    -> defaults(array(
        'directory' => 'site',
        'controller' => 'foobar',
        'action' => 'foobar',
));

It <catcher> is a placeholder and array('catcher'=>'.*') defines the catcher to match the regex .*

Upvotes: 6

Related Questions