$app->get('/new-url', function () use ($app) { return $app->redirect('/old-url', 301); });
$app->get('/user/{id}', function ($request, $response, $args) { // Do some processing here to get the user ID $userId = $args['id']; // Redirect to the user's profile page return $response->withRedirect("/user/$userId/profile"); });This code redirects the user to a URL that includes an ID parameter. The ID parameter is extracted from the URL using the $args variable and then used to construct the new URL. Package Library: The Slim redirect feature is included in the Slim framework package/library.