Slim 3 Redirect - Showing blank page

Hi All,

Request your help on the below issue, the below does not work(redirect) , no errors are reported both in PHP side nor Slim , just a blank page is displayed.

Tried the below, No luck

return $response->withRedirect('login');
return $response->withRedirect($this->router->pathFor('login'));
return $response->withRedirect($this->router->pathFor('login'), 200);
return $response->withHeader('Location', 'login');

$uri = $request->getUri()->withPath($this->router->pathFor('login'));
return $response->withRedirect($uri);

$uri = $request->getUri()->withPath($this->router->pathFor('login'));
return $response->withRedirect($uri, 200);


            <div class="col-md-9 ml-sm-auto col-lg-10 main">
                    {% block content %}{% endblock %}


{% extends "index.html" %}
{% block content%}
    <p>Welcome to Login Page</p>
{% endblock %}

PHP Code

define("ROOT_PATH", 'https://'.$_SERVER['HTTP_HOST'].'/');

$loginauthMiddleware = function($request, $response, $next) {
    $route = $request->getAttribute('route');
    if (empty($route)) { throw new \Slim\Exception\NotFoundException($request, $response); }
    $routeName = $route->getName();
    $groups = $route->getGroups();
    $methods = $route->getMethods();
    $arguments = $route->getArguments();
    $publicRoutesArray = array('login', 'allow');
    if(empty($_SESSION['user']) && (!in_array($routeName, $publicRoutesArray))) {
       **$uri = $request->getUri()->withPath($this->router->pathFor('login'));**
**       return $response->withRedirect($uri, 200);**
    } else { $response = $next($request, $response); }
    return $response;

$app->get('/login', function($request, $response) use($app) {
      return $this->view->render($response, 'page_login.html');

$app->post('/login', function ($request, $response, $args) {
      $user = $_POST['Username'];
      $pass = $_POST['Password'];
      $au = new authendication();
      $result = $au->vaildateUser($user, $pass);
      if($result == "Successful") {
         $_SESSION['user'] = $user;
         return $this->view->render($response, 'page_dashboard.html');

$app->get('/', function($request, $response) use($app) {
      return $this->view->render($response, 'page_home.html');

$app->get('/dashboard', function($request, $response, $args) use($app) {
      return $this->view->render($response, 'page_serverlist.html');

Check the status code you are returning. Many (most?) browsers will not redirect unless the status code is 301 or 302.

Hi Alffonse,

The issue seem to be in Slim version 3.11 where as we are using Slim 3.12.1 and more over if we make the changes as below it is working, In Apache “/admin” is a separate location from the Document Root(/var/www/test)


define("ROOT_PATH", 'https://'.$_SERVER['HTTP_HOST'].'/');

define(“ROOT_PATH”, ‘https://’.$_SERVER[‘HTTP_HOST’].’/admin/’);

Hi Alffonse,

As the git hub it states the issue is with the browser and not with Slim, which does seem to be correct as we tested with Chrome(81.0.4044.138),Firefox(76.0.1), IE 11, IE Edge, Opera(68.0.3618.104) it is not working in any of the web browser, and more over it state that is wont work only when status code is used but it our case it does not not neither ways.