使用 Klein-PHP 过滤请求

Using Klein-PHP to filter requests

我在 PHP 项目中使用 Klein.php 进行路由。我的项目目录具有以下结构:

myProject
|
*---Restricted--
|              |
|              *---index.php
|              |
|              *---blah.html
|              |
|              *---some_directory
|
|
*---some_other_directories
|
*---index.html
|
*---fun.html
|
*---css
|
*---js

我想要的是只处理对 Restricted 文件夹的所有请求。对于其他一切,我只希望服务器完成其工作,即只提供其余文件。

我该如何实现?

编辑

我已将其配置为 CORY 的回答:

// .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

// index.php

<?php

    require_once __DIR__ . '/vendor/autoload.php';

    $klein = new \Klein\Klein();

    $klein->respond('@^/Restricted/', function () {
       // checking if authenticated user
    });

    $klein->dispatch();

?>

就在 Github page for Klein.phpRouting 部分有这个小例子:

// Match all requests that _don't_ start with /admin
$klein->respond('!@^/admin/', ...

我想你基本上想要 相反的(匹配所有 do/restricted 开头的请求),所以让我们删除!(否定)并替换正确的文件夹名称:

// Match all requests that start with /Restricted
$klein->respond('@^/Restricted/', ...