# Unable to access page unless I enter trailing slash

**URL:** <https://discourse.slimframework.com/t/unable-to-access-page-unless-i-enter-trailing-slash/1121>\
**Category:** Questions\
**Created:** [February 2, 2017, 1:30pm UTC](https://discourse.slimframework.com/t/unable-to-access-page-unless-i-enter-trailing-slash/1121 "2017-02-02T13:30:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bharat](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@bharat](https://discourse.slimframework.com/u/bharat)\
**Post date:** [February 2, 2017, 1:30pm UTC](https://discourse.slimframework.com/t/unable-to-access-page-unless-i-enter-trailing-slash/1121/1 "2017-02-02T13:30:32Z")

</div>

Hi,

I’ve defined my routes like:

```
$app->get('/', function ($request, $response, $args) use ($app) {
});

```

And created multiple pages like this only.

Now, I can access the site if I type url like:  
[http://domain.com/user/](http://domain.com/user/)

But I’m unable to access the page if I type url like:  
[http://domain.com/user](http://domain.com/user)

Is there any way to automatically change url from w/o trailing slash to w/ trailing slash ?

Thank you.

---

<div class="post-metadata">

**Author:** ![robrothedev](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/robrothedev/32/137_2.png) [@robrothedev](https://discourse.slimframework.com/u/robrothedev)\
**Post date:** [February 2, 2017, 2:07pm UTC](https://discourse.slimframework.com/t/unable-to-access-page-unless-i-enter-trailing-slash/1121/2 "2017-02-02T14:07:00Z")

</div>

@bharat I’ve use this middleware for my apps and it works well:

[https://www.slimframework.com/docs/cookbook/route-patterns.html](https://www.slimframework.com/docs/cookbook/route-patterns.html)

```
// removes last backslash so /route or /route/ will work
$app->add(function ($request, $response, $next) {
    $uri = $request->getUri();
    $path = $uri->getPath();

    if ($path != '/' && substr($path, -1) == '/') {
	    $uri = $uri->withPath(substr($path, 0, -1));
	    return $response->withRedirect((string)$uri, 301);
    }
    return $next($request, $response);
});

```

Alternatively you could use this for your route:

```
$app->get('/user[/]','');

```

But you would have to do this on all of your routes.

---

<div class="post-metadata">

**Author:** ![bharat](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@bharat](https://discourse.slimframework.com/u/bharat)\
**Post date:** [February 3, 2017, 4:40am UTC](https://discourse.slimframework.com/t/unable-to-access-page-unless-i-enter-trailing-slash/1121/3 "2017-02-03T04:40:36Z")

</div>

@robrothedev, Thanks Rob 🙏
