我的需求是做一個(gè)短鏈接系統(tǒng),domain.com/hU2c 這樣的url可以直接訪問短鏈接還原長連接的操作。
但是在做路由的時(shí)候遇到了問題,這是我目前的路由設(shè)置
use Webman\Route;
Route::any('/api/shortURL', [app\controller\Api::class, 'shortURL']);
// 默認(rèn)根路徑就去訪問還原長鏈接
// Route::get('[{path:.+}]', [app\controller\Api::class, 'restore']);
Route::fallback(function ($request){
return (new app\controller\Api::class)->restore($request);
});
如果使用
Route::get('[{path:.+}]', [app\controller\Api::class, 'restore']);
我的/api/shortURL以及其他路由不會生效,會被Route::get('[{path:.+}]'匹配,這樣我無法進(jìn)行其他操作。
于是我想到使用Route::fallback來做最后的匹配,但是翻遍了論壇和文檔,沒有找到合適的解決方案。
跟我類似需求的帖子 http://www.wtbis.cn/q/8597 實(shí)踐后的結(jié)論是 無法使用,顯示404.