# Slim 3 - Placeholders in routes are not working

**URL:** <https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059>\
**Category:** Questions\
**Created:** [April 16, 2020, 7:44am UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059 "2020-04-16T07:44:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bogus](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bogus](https://discourse.slimframework.com/u/bogus)\
**Post date:** [April 16, 2020, 7:44am UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/1 "2020-04-16T07:44:36Z")

</div>

Hello!

Since my newest projekt with Slim3 I went into troubles with the routes. I try to explain by example testing routes:

$app-\>get(’/test/{hallo}’, function ($request, $response, $args) use ($app) {  
print “test ok!”;  
exit;  
});

$app-\>post(’/test/{hallo}’, function ($request, $response, $args) use ($app) {  
print “test ok!”;  
exit;  
});

$app-\>post(’/test’, function ($request, $response, $args) use ($app) {  
print “test ok!”;  
exit;  
});

The routes  
GET /test/1234  
POST /test  
are working as expected.

But for  
POST /test/1234  
I get: 405 Method not allowed. Must be one of: **GET**

I’m using latest Slim 3 and testing with Postman

What the hell am I doing wrong?  
TIA for any help!  
Regards from Austria

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [April 16, 2020, 11:48am UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/2 "2020-04-16T11:48:45Z")

</div>

Try to move the `$app->post(’/test/{hallo}’` route above the `$app->get(’/test/{hallo}’` route.

---

<div class="post-metadata">

**Author:** ![bogus](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bogus](https://discourse.slimframework.com/u/bogus)\
**Post date:** [April 16, 2020, 1:15pm UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/3 "2020-04-16T13:15:35Z")

</div>

same problem: 405 Method not allowed. Must be one of: **GET**

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [April 16, 2020, 3:25pm UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/4 "2020-04-16T15:25:48Z")

</div>

I have testet your routes with Slim 4 (not Slim 3) and everything works.  
Maybe you try to upgrade to Slim 4?

---

<div class="post-metadata">

**Author:** ![bogus](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bogus](https://discourse.slimframework.com/u/bogus)\
**Post date:** [April 16, 2020, 5:09pm UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/5 "2020-04-16T17:09:16Z")

</div>

slim 4 is no option because there are about 5 REST API’s which are running with slim 3 for this company, so they won’t change to a different system.

I haven’t had this problem with the existing 5 API’s. (Biggest one hast about 280 routes.)

The only difference here is: I’m using current Version of Slim and installed all with composer and my project with GIT. The other ones was more like copy & paste sources, and than rewrite the routes and functions.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [April 16, 2020, 7:23pm UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/6 "2020-04-16T19:23:58Z")

</div>

For fun I also tried your routes in Slim 3 and it works too.

```php
$app->get('/test/{hallo}', function ($request, $response, $args) {
    print "test ok! 1";
    exit;
});

$app->post('/test/{hallo}', function ($request, $response, $args) {
    print "test ok! 2";
    exit;
});

$app->post('/test', function ($request, $response, $args) {
    print "test ok! 3";
    exit;
});

```

![image](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/4/40792796c920d212c07cd8b3c8602816532b7ba8.png)

---

<div class="post-metadata">

**Author:** ![bogus](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bogus](https://discourse.slimframework.com/u/bogus)\
**Post date:** [April 17, 2020, 2:55pm UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/7 "2020-04-17T14:55:14Z")

</div>

seem’s like I’ll get one step back and just copy the sources from another working api, and replacing there routes.  
something might be broken…

---

<div class="post-metadata">

**Author:** ![bogus](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bogus](https://discourse.slimframework.com/u/bogus)\
**Post date:** [April 20, 2020, 7:30am UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/8 "2020-04-20T07:30:57Z")

</div>

I’ve found the reason!  
The regex for the placeholders doesn’t work like normal regex.  
Following route caused the problems:  
$app-\>post(’/buckets/{bucket\_name:[a-Z0-9]+}’,

a-Z seems to break the method were this regex is used. Switched to  
$app-\>post(’/buckets/{bucket\_name:[a-zA-Z0-9]+}’,  
and everything is fine now.

That cost me a lot of time ☹

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [April 20, 2020, 8:31am UTC](https://discourse.slimframework.com/t/slim-3-placeholders-in-routes-are-not-working/4059/9 "2020-04-20T08:31:55Z")

</div>

Yes, the placeholder regex is case sensitive.
