如何在 PHP 的 Slim 框架中重定向到不同的域?

How to redirect to different domain in Slim framework of PHP?

使用 Slim 我们可以使用如下路由:

$app->get('/path', function() {
    include 'content.php';
});

我们还可以重定向到同一域的任何其他路径,例如:

$app->get('/path2', function () use ($app) {
    $app->redirect('/redirect-here');
});

但我想重定向到一些不同的域,下面的none正在工作:

$app->get('/feeds', function(){
    $app->redirect('http://feeds.example.com/feed');
});

这显示空白页:

$app->get('/feeds', function() {
    header("Location: http://feeds.example.com/feed");
});

在 Slim 3 中,您应该在 Response 对象上使用 withRedirect 方法:

$app->get('/feeds', function ($request, $response, $args) {
    return $response->withRedirect('http://feeds.example.com/feed', 301);
});

仅适用于 Slim 2,您可以:

$app->get('/feeds', function() use ($app) {
    $app->redirect('http://feeds.example.com/feed');
});