2016-11-17 69 views

回答

1

有两种可能性

  1. 指定可选/

    $app->get('/admin[/]', function(){ 
        # code here 
    }); 
    
  2. 添加中间件与结束/的URL不重定向路由。

    use Psr\Http\Message\RequestInterface as Request; 
    use Psr\Http\Message\ResponseInterface as Response; 
    
    $app->add(function (Request $request, Response $response, callable $next) { 
        $uri = $request->getUri(); 
        $path = $uri->getPath(); 
        if ($path != '/' && substr($path, -1) == '/') { 
         // permanently redirect paths with a trailing slash 
         // to their non-trailing counterpart 
         $uri = $uri->withPath(substr($path, 0, -1)); 
    
         if($request->getMethod() == 'GET') { 
          return $response->withRedirect((string)$uri, 301); 
         } 
         else { 
          return $next($request->withUri($uri), $response); 
         } 
        } 
    
        return $next($request, $response); 
    }); 
    

    (来源:http://www.slimframework.com/docs/cookbook/route-patterns.html