Redirection routes are different from normal routes as they perform an actual
header redirection if a match is found. The redirection can occur within your
application or redirect to an outside location.
Examples:
Router::redirect('/home/*', array('controller' => 'posts', 'action' => 'view'), array('persist' => true));
Redirects /home/* to /posts/view and passes the parameters to /posts/view. Using an array as the
redirect destination allows you to use other routes to define where a URL string should be redirected to.
Router::redirect('/posts/*', 'http://google.com', array('status' => 302));
Redirects /posts/* to http://google.com with a HTTP status of 302
### Options:
- status Sets the HTTP status (default 301)
- persist Passes the params to the redirected route, if it can. This is useful with greedy routes,
routes that end in * are greedy. As you can remap URLs and not loose any passed/named args.
public static redirect ( string $route, array $url, array $options = [] ) : array | ||
$route | string | A string describing the template of the route |
$url | array | A URL to redirect to. Can be a string or a CakePHP array-based URL |
$options | array | An array matching the named elements in the route to regular expressions which that element should match. Also contains additional parameters such as which routed parameters should be shifted into the passed arguments. As well as supplying patterns for routing parameters. |
return | array | Array of routes |