簡體   English   中英

在 Slim3 中將 http|https 與 fasteRoute 匹配

[英]match http|https with fasteRoute in Slim3

我在這里的樣品FastRoute為slim3:

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

使用這個 FastRoute "regex" ([{domaine}[/{notused:.+}]]),我匹配:

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

而 $args['domaine'] 返回“sample.com”。

但我也想匹配這個:

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

添加像這樣的新路線:

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

但最好只有一行。

有任何想法嗎 ?

使用 url 編碼的 url 作為查詢參數會更好。

但是當你真的要使用它時,你也可以正則表達式 http(s) 部分

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

這意味着它需要http然后有 0-1 s

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM