Skip to content

Commit dfa4db3

Browse files
authored
Update route-patterns.md
1 parent f560196 commit dfa4db3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/cookbook/route-patterns.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Trailing / in route patterns
33
---
44

5-
Slim treats a URL pattern with a trailing slash as different to one without. That is, `/user` and `/user/` are different and so can have different callbacks attached.
5+
RawPHP treats a URL pattern with a trailing slash as different to one without. That is, `/user` and `/user/` are different and so can have different callbacks attached.
66

77
For GET requests a permanent redirect is fine, but for other request methods like POST or PUT the browser will send the second request with the GET method. To avoid this you simply need to remove the trailing slash and pass the manipulated url to the next middleware.
88

99
If you want to redirect/rewrite all URLs that end in a `/` to the non-trailing `/` equivalent, then you can add this middleware:
1010

11-
{% highlight php %}
11+
```
1212
use Psr\Http\Message\RequestInterface as Request;
1313
use Psr\Http\Message\ResponseInterface as Response;
1414
@@ -30,12 +30,12 @@ $app->add(function (Request $request, Response $response, callable $next) {
3030
3131
return $next($request, $response);
3232
});
33-
{% endhighlight %}
33+
```
3434

3535
Alternatively, consider [oscarotero/psr7-middlewares' TrailingSlash](//github.com/oscarotero/psr7-middlewares#trailingslash) middleware which also allows you to force a trailing slash to be appended to all URLs:
3636

37-
{% highlight php %}
37+
```
3838
use Psr7Middlewares\Middleware\TrailingSlash;
3939
4040
$app->add(new TrailingSlash(true)); // true adds the trailing slash (false removes it)
41-
{% endhighlight %}
41+
```

0 commit comments

Comments
 (0)