# Problem with $app-\>redirect

**URL:** <https://discourse.slimframework.com/t/problem-with-app-redirect/1350>\
**Category:** Questions\
**Created:** [March 31, 2017, 8:05am UTC](https://discourse.slimframework.com/t/problem-with-app-redirect/1350 "2017-03-31T08:05:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![st3v3j0b5](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@st3v3j0b5](https://discourse.slimframework.com/u/st3v3j0b5)\
**Post date:** [March 31, 2017, 8:05am UTC](https://discourse.slimframework.com/t/problem-with-app-redirect/1350/1 "2017-03-31T08:05:21Z")

</div>

have a problem with Slim V2. The problem is that i can’t redirect to my dashboard page after login.

this is my index.php code:  
\<?

```
    require_once 'vendor/autoload.php';
    //Inizio le inclusioni necessarie
    require("config/database.php");
    require_once("vendor/dabble/dabble/src/Dabble/Database.php");
    require_once("vendor/dabble/dabble/src/Dabble/Result.php");

    
    session_name('GeCo');
    session_start();
    date_default_timezone_set("Europe/Rome");

    $db = new Dabble\Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    global $db;

    $app = new \Slim\Slim(array(
        'templates.path' => './template',
        'debug' => true
    ));

    \Slim\Slim::registerAutoloader();

    require 'app/GeCo.php';

   
    $app->run();

?>

```

And this is GeCo.php markup:

```
<?php

    require_once('classes/Login.php');
    use login\Login;

    $app->get('/', function () use ($app) {

        $app->redirect('/dashboard');

    });

    $app->get('/login', function () use ($app) {

        $page = 'login.php';
        $app->render($page);

    });

    $app->get('/dashboard', function () use ($app) {

        $page = 'dashboard.php';
        $app->render($page);

    })->name('dash');;

    $app->post('/login', function () use ($app,$db) {

        try {

            $result=[];
            $username = $_POST['username'];
            $password = $_POST['password'];

            $login = new Login($db);
            $result = $login->checkLogin($username,$password);

        }catch (\Exception $e) {
            error_log(json_encode(print_r($e->getTrace(), 1)));
        } finally {

            if ($result) {

                $_SESSION['loggedUser'] = $username;
                $_SESSION['password']=md5($password);
                $app->redirect('/dashboard');
            } else {

                header ( 'Content-Type: application/json' );
                echo json_encode('No user found.');
                exit();

            }

        }

    });

```

And finally this is my .htaccess file:

```
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```

The problem is that the instruction “$app-\>redirect(’/dashboard’);” doesn’t work…The browser still remain in login page but in Network inspector i see that the dashboard page is rendered and the route called! I’m getting really mad 🙂

I have also tried many methods with the “$ response” but I did not succeed.

please help me 🙂

Thanks

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [March 31, 2017, 8:48pm UTC](https://discourse.slimframework.com/t/problem-with-app-redirect/1350/2 "2017-03-31T20:48:22Z")

</div>

I have no experience with Slim Framework v2, but the [documentation](http://docs.slimframework.com/routing/helpers/) states:

> Please be aware that the following application instance method helpers halt(), pass(), redirect() and stop() are implemented using Exceptions. Each will throw a \Slim\Exception\Stop or \Slim\Exception\Pass exception.

And also

> Where possible in your own application you should use typed Exceptions so your catch blocks are more targeted rather than swallowing all Exceptions.

Maybe a try/catch block is interfering with the exception thrown by `$app->redirect`?
