use('/', function($response) { $response->setPoweredBy('Awaki+Index'); }); $router->get('/', function() { $body = ''; $body .= 'Awaki'; $body .= 'Redirect service - OK'; return $body; }); $router->get('/:id', function($response, $request, $id) use ($db) { $getInfo = $db->prepare('SELECT `redir_url` FROM `awk_redirects` WHERE `redir_id` = ? OR `redir_vanity` = ?'); $getInfo->addParameter(1, $id, DbType::INTEGER); $getInfo->addParameter(2, $id, DbType::STRING); $getInfo->execute(); $info = $getInfo->getResult(); if(!$info->next()) return 404; $targetUrl = $info->getString(0); $params = $request->getParamString(); if(!empty($params)) $targetUrl .= '?' . $params; $response->redirect($targetUrl); }); $router->dispatch();