1

here my sample FastRoute for slim3 :

$app->get('/api/search/[{domaine}[/{notused:.+}]]', function ($request, $response, $args) {
    return $this->renderer->render($response, 'index.phtml', $args);
});

with this FastRoute "regex" ([{domaine}[/{notused:.+}]]), I match :

/api/search/sample.com  
/api/search/sample.com/test  
/api/search/  

And $args['domaine'] return "sample.com".

but I want to match this too :

/api/search/http://sample.com  
/api/search/https://sample.com  

add new route like this work :

$app->get('/api/search/http://[{domaine}[/{notused:.+}]]' ...   
$app->get('/api/search/https://[{domaine}[/{notused:.+}]]' ...  

But it's better to have just one line.

Any ideas ?

trucky
  • 11
  • 1

1 Answers1

1

It would be better when you use an url encoded url as query parameter.

But when you really what to use this, you could regex the http(s) part as well

$app->get('/api/search/{urlSchema:https?}://[{domaine}[/{notused:.+}]]', ..);

that means it requires http and then have 0-1 s.

jmattheis
  • 10,494
  • 11
  • 46
  • 58