# Trailing slash is paths

**URL:** <https://discourse.slimframework.com/t/trailing-slash-is-paths/6170>\
**Category:** Questions\
**Created:** [September 3, 2025, 6:21pm UTC](https://discourse.slimframework.com/t/trailing-slash-is-paths/6170 "2025-09-03T18:21:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kAlvaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/kalvaro/32/730_2.png) [@kAlvaro](https://discourse.slimframework.com/u/kAlvaro)\
**Post date:** [September 3, 2025, 6:21pm UTC](https://discourse.slimframework.com/t/trailing-slash-is-paths/6170/1 "2025-09-03T18:21:11Z")

</div>

I found there’s a route in my site that could only be reached if I type the trailing slash:

```php
$app->group('/foo', function (RouteCollectorProxy $group) {
    $group->get('/', Pages\Foo::class); // 👈 This one

    $group->any('/logs.html', Pages\Foo::class . ':logs');
    $group->get('/scripts.html', Pages\Foo::class . ':scripts');
});

```

I fixed it by duplicating the route definition. It works, but it feels ugly.

```php
    $group->get('/', Pages\Foo::class);
    $group->get('', Pages\Foo::class);

```

I also tried out out the [middlewares/trailing-slash](https://github.com/middlewares/trailing-slash) package linked in the [Trailing / in route patterns](https://www.slimframework.com/docs/v4/cookbook/route-patterns.html) chapter of Slim cook book to normalise trailing slashes in paths (I’ll probably force removal) but I can’t see that it makes any difference. I’ve tried adding it first and last, and nothing seems to happen. No redirection happens.

I found [this snippet](https://discourse.slimframework.com/t/unable-to-access-page-unless-i-enter-trailing-slash/1121/2) in the forum, but it throws `ArgumentCountError` in current version. It probably has an easy fix, but this silly issue is starting to get time consuming for me.

How do people deal with trailing slashes and canonical paths in Slim v4?

---

<div class="post-metadata">

**Author:** ![drinkynet](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/drinkynet/32/1296_2.png) [@drinkynet](https://discourse.slimframework.com/u/drinkynet)\
**Post date:** [September 4, 2025, 2:17pm UTC](https://discourse.slimframework.com/t/trailing-slash-is-paths/6170/2 "2025-09-04T14:17:33Z")

</div>

> [@kAlvaro](#):
>
> ```auto
> $app->group('/foo', function (RouteCollectorProxy $group) {
> $group->get('/', Pages\Foo::class); // 👈 This one
> 
> ```

try this: `$group→get(‘[/]’, Pages\Foo::class);`

---

<div class="post-metadata">

**Author:** ![kAlvaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/kalvaro/32/730_2.png) [@kAlvaro](https://discourse.slimframework.com/u/kAlvaro)\
**Post date:** [September 4, 2025, 3:50pm UTC](https://discourse.slimframework.com/t/trailing-slash-is-paths/6170/3 "2025-09-04T15:50:54Z")

</div>

Ah, yes. I totally missed [optional segments](https://www.slimframework.com/docs/v4/objects/routing.html#optional-segments). Thank you!

---

<div class="post-metadata">

**Author:** ![kAlvaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/kalvaro/32/730_2.png) [@kAlvaro](https://discourse.slimframework.com/u/kAlvaro)\
**Post date:** [September 4, 2025, 4:16pm UTC](https://discourse.slimframework.com/t/trailing-slash-is-paths/6170/4 "2025-09-04T16:16:06Z")

</div>

I eventually understood that the middleware package needs to be configured this way if you want a redirection:

```php
$app->add(new TrailingSlash()->redirect()); // Don't miss ->redirect() !!!

```

Otherwise, it merely populates the internal URI field for the request object. I thought the examples in the documentation were illustrating something else.
