How to get redirected to correct page with silex?

When I go to
(please note /index.php/ as part of the url.)
After successful login, I get redirects to
and that’s correct.

but the login screen url should not have /index.php/ as this is Silex restapi.

But when I try login without /index.php/ that would be
after login this time, I get redirected to new/index.php instead of /welcome/ like last time.

Please help.

my code is below:


$app = SilexApplication;
$app->mount('/login', new RoutersLogin());


namespace Routers;
use SilexApplication;
use SilexApiControllerProviderInterface;
use SymfonyComponentHttpFoundationRequest ;

class Login implements ControllerProviderInterface
      public function connect(Application $app)
      // creates a new controller based on the default route
      $controllers = $app['controllers_factory'];
      $controllers->get('/', 'Controllers\Login::index');
      $controllers->post('/', 'Controllers\Login::validate');

      return $controllers;



namespace Controllers;
use SilexApplication;
use SymfonyComponentHttpFoundationRequest;

class Login {

      public function index(Request $request, Application $app) 
             return $app['twig']->render('login.html');

      public function validate(Request $request, Application $app) 

             // validation goes here
             if ( // invalid ) {
                 return $app['twig']->render('login.html');
             } else {
                 // valid 
                 header("Location: /welcome");


<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon.ico|apple-touch-icon.*.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]

I guess I discovered the issue, the login form is:

 <form method="post" action="index.php">

instead of posting data to
So how the action url must be? I tried action=”/new/login” and it doesn’t work. I get no route for POST /login. but this is defined in Routers/Login.php, so why should I get this?
Please advise.

For more info please click here

Have a question or need a custom quote?