【发布时间】:2017-01-05 03:51:09
【问题描述】:
我正在玩 Silex,试图在共享网络托管中将其用作 RESTful json api。主机有 Apache Web 服务器。我希望 Silex 应用程序位于我暂时称为 experiments/api 的文件夹中,因此该应用程序与 webroot 处于不同的级别。根据documentation,我放在Silex 应用文件夹中的.htaccess 文件如下所示:
RewriteEngine On
RewriteBase /experiments/api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ src/index.php [QSA,L]
(意味着应用程序位于/experiments/api 文件夹中,主控制器文件位于src 文件夹中,名为index.php)
这样就完成了工作(即 Silex 应用程序接收到 /experiments/api/ 的请求),但不便之处在于应用程序现在看到了路径名的这个 /experiments/api/ 前缀。
例如。当我向 /experiments/api/hello 发送 GET 请求时,我希望应用程序忽略 /experiments/api 部分,并仅匹配 /hello 路由。但目前该应用尝试匹配整个/experiments/api/hello 路径。
有没有办法重置 Silex 的根路由以包含路径的常量部分?我浏览了文档,但找不到答案。
【问题讨论】: