Reputation: 2172
Using Slim we can use routes like:
$app->get('/path', function() {
include 'content.php';
});
We can also redirect to any other path of same domain like:
$app->get('/path2', function () use ($app) {
$app->redirect('/redirect-here');
});
But I want to redirect to some different domain and none of below is working:
$app->get('/feeds', function(){
$app->redirect('http://feeds.example.com/feed');
});
This shows blank page:
$app->get('/feeds', function() {
header("Location: http://feeds.example.com/feed");
});
Upvotes: 1
Views: 3550
Reputation: 8688
In Slim 3, you should use the withRedirect
method on the Response
object:
$app->get('/feeds', function ($request, $response, $args) {
return $response->withRedirect('http://feeds.example.com/feed', 301);
});
For Slim 2 only, you can do:
$app->get('/feeds', function() use ($app) {
$app->redirect('http://feeds.example.com/feed');
});
Upvotes: 4