There is nothing built in with Kohana to handle redirection within the routes.
What I typically do is route to a redirect controller which has all my redirect rules and I process the redirect there.
質問
I am using Kohana Framework 3.2
Usually in my bootstrap file, I can setup a Route::set like this:
Route::set('faq', 'faq')->defaults(array('controller' => 'home', 'action' => 'faq'));
This does so example.com/faq points to my controller home, action faq.
I would like to know if I can setup a redirection this way also?
So I can say that example.com/faq should redirect to example.com/thegreatfaqs?
Or must use route::set like the above, to a controller that then request redirects to /thegreatfaqs ?
解決
There is nothing built in with Kohana to handle redirection within the routes.
What I typically do is route to a redirect controller which has all my redirect rules and I process the redirect there.
他のヒント
You can do this using a Route filter
, but I think this is a Bad Idea since you're interrupting the normal flow of a Kohana application.
Route::set('redirecturl', 'redirecturl')
->filter(function($route, $params, $request) {
header('Location: http://www.example.com/');
exit;
});
I'd suggest a Redirect rule (Apache .htaccess) or a redirect from a dedicated controller action as mentioned by Scott is a much cleaner solution.
You can set your route like this....>
Route::set('faq', 'thegreatfaqs(/<action>(/<id>))')
->defaults(array(
'controller' => 'home',
'action' => 'faq',
));