# Slim 3 Redirect - Showing blank page

**URL:** <https://discourse.slimframework.com/t/slim-3-redirect-showing-blank-page/4172>\
**Category:** Questions\
**Created:** [May 18, 2020, 2:09pm UTC](https://discourse.slimframework.com/t/slim-3-redirect-showing-blank-page/4172 "2020-05-18T14:09:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 18, 2020, 2:09pm UTC](https://discourse.slimframework.com/t/slim-3-redirect-showing-blank-page/4172/1 "2020-05-18T14:09:00Z")

</div>

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**

```auto
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);

```

**index.html**

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

```

**page\_login.html**

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

```

**PHP Code**

```auto
session_start();
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->add(loginauthMiddleware);

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

$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');
      }
})->setName('login');

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

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

```

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [May 18, 2020, 2:56pm UTC](https://discourse.slimframework.com/t/slim-3-redirect-showing-blank-page/4172/2 "2020-05-18T14:56:53Z")

</div>

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

> <https://github.com/slimphp/Slim/issues/2517>
>
> PHP version : 7.2.5
> Slim version 3.11
> Hello,
> I just started a new project with Slim yesterday and I realized that my redirections don't...

---

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 18, 2020, 4:08pm UTC](https://discourse.slimframework.com/t/slim-3-redirect-showing-blank-page/4172/3 "2020-05-18T16:08:54Z")

</div>

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)

**Original**

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

```

define(“ROOT\_PATH”, ‘https://’.$\_SERVER[‘HTTP\_HOST’].’/admin/’);

```auto

```

---

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 18, 2020, 4:26pm UTC](https://discourse.slimframework.com/t/slim-3-redirect-showing-blank-page/4172/4 "2020-05-18T16:26:34Z")

</div>

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.
