How do I perform a redirect in Concrete 5.7?

1.3k Views Asked by At

What's the correct way of performing a server-side redirect in custom Concrete5 code (5.7+)?

2

There are 2 best solutions below

0
On

Another solution would be as follows:

$response = \Redirect::to('/URL-HERE');
$response->send();
exit;

or

return \Redirect::to('/URL-HERE')->send();

Sidenote: The url provided must not be absolute. For example: '/dashboard/reports/logs'

0
On

I discovered this is the best way:

(new RedirectResponse('/URL-HERE'))->send();          // 302 temporary
(new RedirectResponse('/URL-HERE', 301))->send();     // 301 permanent

You should be able to call this from (almost) anywhere within the app and not worry about namespaces since it has an alias in /concrete/config/app.php.