fabpot/Silex — Issue #253: Annoying issue with trailing slashes
Author: KenTiN
Created: 2012-02-14 21:23:10+00:00
State: open

Hi there,

Sorry in advance for my bad english (french ftw). I will try to be as clearer as possible!

I'm experiencing a kind of annoying issue with trailing slashes.

For example, i've declared a service of Login which i've mounted on ```/login```

```
$app->mount('/login', new MyApp\Provider\LoginServiceProvider());
```

I want the route ```/login``` to be matched with a default controller of my Service. But i've failed at doing this.

Here is my ServiceProvider connect method :

```
$controllers = new ControllerCollection();

// I want this route to be /login and /login/ (and not just /login/)
$controllers->get('/', function (Application $app) {
return $app['twig']->render('login.twig');
});

// Url is /login/password
$controllers->get('/password', function (Application $app) {
return $app['twig']->render('pasword.twig');
});

return $controllers;
```

The only route that matches is ```/login/```. When i try ```/login```, an exception is threw (No route found...). I've tried a little trick that works, but i find it not really good, it's just :
```
$app->get('/login', function () use ($app) {
return $app->redirect('login/');
});
```

I've noticed that when i change the mount point of my service to ```/login.html``` and go to that page, it adds automatically the trailing slash (the url become ```/login.html/```) without any redirect rule.

Is this a bug or the normal behavior ? Is my web browser adding it automatically (same behavior on Chrome and FF) ?

Thanks in advance.