views:

31

answers:

2

Hi,

I was wondering how to do a redirect in the routes of a cakephp application.

I simply want to redirect on url /xxx to /yyy

I don't want to have to set up a controller or and action in the pages controller just to redirect a url.

Is there a way to do it in the routing?

Cheers.

+1  A: 

Routes are used to connect URLs to controller actions. That's all they do. They do not redirect.

As @Nik suggested, if you don't want to make a controller for it, use .htaccess rules.

deceze
Well cake is based pretty heavily on rails, which does consider redirection to be part of routing. Rails has it's...match "/xxx" => redirect("/yyy")I assumed because there so similar cake would have one too. Routing is about dispatching a url to a controller/action, even if that url need's redirecting.
Smickie
@Smickie Interesting. But Cake isn't Rails. :) You could of course hack around it, especially if using a custom URL parser class, but you probably shouldn't. What's your use case? Do you want to redirect expired URLs to new ones?
deceze
I've added a redirect to the cake roadmap, it'll be coming in a future version.
Smickie
A: 

@smickie, its not rails, the proper way to do it is use Controller::beforeRedirect() look it up in the api for the params that it uses.

dogmatic69
I've added a redirect to the cake roadmap, it'll be coming in a future version.
Smickie